Class | Ramaze::Helper::BlueForm::Form
In: | lib/ramaze/helper/blue_form.rb
Parent: | Object

Main form class that contains all the required methods to generate form specific tags, such as textareas and select boxes. Do note that this class is not thread-safe so you should modify it only within one thread of execution.

### Methods

build checkbox fieldset file hidden input_checkbox input_file input_hidden input_password input_radio input_submit input_text legend new password radio select submit text textarea to_s

### Attributes

form_values | [R] |
g | [R] |

### Public Class methods

new(form_values, options)

Constructor method that generates an instance of the Form class.

@param [Object] form_values Object containing the values for each form

     field.

@param [Hash] options A hash containing any additional form attributes. @return [Object] An instance of the Form class.

### Public Instance methods

build(form_errors = {}) {|self| ...}

Builds the form by generating the opening/closing tags and executing the methods in the block.

@param [Hash] form_errors Hash containing all form errors (if any).

checkbox(label, name, checked = nil, args = {})

Alias for input_checkbox

fieldset(&block)

Generate a fieldset tag.

@param [Block] &block The form elements to display inside the fieldset. @example

     form_for(@data, :method => :post) do |f|
       f.fieldset do
         f.legend 'Hello, world!'
       end
     end

file(label, name, args = {})

Alias for input_file

hidden(name, value = nil, args = {})

Alias for input_hidden

input_checkbox(label, name, checked = nil, args = {})

Generate an input tag with a type of "checkbox".

If you want to have multiple checkboxes you can either use an array or a hash. In the case of an array the values will also be used as text for each checkbox. When using a hash the key will be displayed and the value will be the value of the checkbox. Example:

        @data = Class.new
          attr_reader :gender_arr
          attr_reader :gender_hash

          def initialize
            @gender_arr  = ['male', 'female']
            @gender_hash = {"Male" => "male", "Female" => "female"}
          end
        end.new

        form_for(@data, :method => :post) do |f|
          f.input_checkbox "Gender", :gender_arr
          f.input_checkbox "Gender", :gender_hash
        end

@example

     form_for(@data, :method => :post) do |f|
       f.input_checkbox 'Remember me', :remember_user
     end

@param [String] label The text to display inside the label tag. @param [String Symbol] name The name of the checkbox. @param [String/Array] checked String or array that indicates which

     value(s) should be checked.

@param [Hash] args Any additional HTML attributes along with their

     values.

@option args [String/Symbol] :id The value to use for the ID attribute. @option args [Array] :values An array containing the possible values

     for the checkboxes.

@option args [String/Symbol] :span_class The class to use for the

     <span> element that's wrapped around the checkbox.

@option args [TrueClass/FalseClass] :show_value When set to false the

     value of each checkbox won't be displayed to the right of the
     checkbox. This option is set to true by default.

@option args [TrueClass/FalseClass] :show_label When set to true

     (default) the label for the checkbox will be displayed. Setting this
     to false will hide it.

input_file(label, name, args = {})

Generate a field for uploading files.

@param [String] label The text to display inside the label tag. @param [String Symbol] name The name of the radio tag. @param [Hash] args Any additional HTML attributes along with their

     values.

@example

     form_for(@data, :method => :post) do |f|
       f.input_file 'Image', :image
     end

input_hidden(name, value = nil, args = {})

Generate a hidden field. Hidden fields are essentially the same as text fields except that they aren‘t displayed in the browser.

@param [String Symbol] name The name of the hidden field tag. @param [String] value The value of the hidden field @param [Hash] args Any additional HTML attributes along with their

     values.

@example

     form_for(@data, :method => :post) do |f|
       f.input_hidden :user_id
     end

input_password(label, name, args = {})

Generate an input tag with a type of "password" along with a label. Password fields are pretty much the same as text fields except that the content of these fields is replaced with dots. This method has the following alias: "password".

@param [String] label The text to display inside the label tag. @param [String Symbol] name The name of the password field. @param [Hash] args Any additional HTML attributes along with their

     values.

@example

     form_for(@data, :method => :post) do |f|
       f.input_password 'My password', :password
     end

input_radio(label, name, checked = nil, args = {})

Generate an input tag with a type of "radio".

If you want to generate multiple radio buttons you can use an array just like you can with checkboxes. Example:

        @data = Class.new
          attr_reader :gender_arr
          attr_reader :gender_hash

          def initialize
            @gender_arr  = ['male', 'female']
            @gender_hash = {"Male" => "male", "Female" => "female"}
          end
        end.new

        form_for(@data, :method => :post) do |f|
          f.input_radio "Gender", :gender_arr
          f.input_radio "Gender", :gender_hash
        end

For more information see the input_checkbox() method.

@param [String] label The text to display inside the label tag. @param [String Symbol] name The name of the radio button. @param [String] checked String that indicates if (and which) radio

     button should be checked.

@param [Hash] args Any additional HTML attributes along with their

     values.

@see input_checkbox() @example

     form_for(@data, :method => :post) do |f|
       f.input_radio 'Gender', :gender
     end

input_submit(value = nil, args = {})

Generate a submit tag (without a label). A submit tag is a button that once it‘s clicked will send the form data to the server.

@param [String] value The text to display in the button. @param [Hash] args Any additional HTML attributes along with their

     values.

@example

     form_for(@data, :method => :post) do |f|
       f.input_submit 'Save'
     end

input_text(label, name, args = {})

Generate an input tag with a type of "text" along with a label tag. This method also has the alias "text" so feel free to use that one instead of input_text.

@param [String] label The text to display inside the label tag. @param [String Symbol] name The name of the text field. @param [Hash] args Any additional HTML attributes along with their

     values.

@example

      form_for(@data, :method => :post) do |f|
        f.input_text 'Username', :username
      end

legend(text)

Generate a <legend> tag.

@param [String] text The text to display inside the legend tag. @example

      form_for(@data, :method => :post) do |f|
        f.legend 'Ramaze rocks!'
      end

password(label, name, args = {})

Alias for input_password

radio(label, name, checked = nil, args = {})

Alias for input_radio

select(label, name, args = {})

Generate a select tag along with the option tags and a label.

@param [String] label The text to display inside the label tag. @param [String Symbol] name The name of the select tag. @param [Hash] args Hash containing additional HTML attributes. @example

     form_for(@data, :method => :post) do |f|
       f.select 'Country', :country_list
     end

submit(value = nil, args = {})

Alias for input_submit

text(label, name, args = {})

Alias for input_text

textarea(label, name, args = {})

Generate a text area.

@param [String] label The text to display inside the label tag. @param [String Symbol] name The name of the textarea. @param [Hash] args Any additional HTML attributes along with their

     values.

@example

     form_for(@data, :method => :post) do |f|
       f.textarea 'Description', :description
     end

to_s()

Method used for converting the results of the BlueForm helper to a string

@return [String] The form output

[Validate]