Module: Brut::FrontEnd::Forms::InputDeclarations
- Included in:
- Brut::FrontEnd::Form
- Defined in:
- lib/brut/front_end/forms/input_declarations.rb
Overview
Extended by Brut::FrontEnd::Form to allow declaring inputs. Do not use this module directly. Instead, call #input or #select from within your form's class definition.
Instance Method Summary collapse
-
#button(name) ⇒ Object
Declares a named button for this form, which is required in order to have this button's name and value sent to the back.
-
#input(name, attributes = {}) ⇒ Object
Declares an input for this form, to be modeled via an HTML
<INPUT>tag. -
#inputs_from(other_class) ⇒ Object
Copy the inputs from another form into this one.
-
#radio_button_group(name, attributes = {}) ⇒ Object
Declares a radio button group, which will manifest as one or more
<input type="radio">tags that all use the same value for theirnameattribute. -
#select(name, attributes = {}) ⇒ Object
Declares a select for this form, to be modeled via an HTML
<SELECT>tag.
Instance Method Details
#button(name) ⇒ Object
Declares a named button for this form, which is required in order to have this button's name and
value sent to the back. This will generate a <button> tag. To use <input type="submit">, #input should
be used instead.
18 19 20 21 22 |
# File 'lib/brut/front_end/forms/input_declarations.rb', line 18 def (name) self.add_input_definition( Brut::FrontEnd::Forms::ButtonInputDefinition.new(name:) ) end |
#input(name, attributes = {}) ⇒ Object
Declares an input for this form, to be modeled via an HTML <INPUT> tag.
8 9 10 11 12 |
# File 'lib/brut/front_end/forms/input_declarations.rb', line 8 def input(name,attributes={}) self.add_input_definition( Brut::FrontEnd::Forms::InputDefinition.new(**(attributes.merge(name: name))) ) end |
#inputs_from(other_class) ⇒ Object
Copy the inputs from another form into this one. This is useful when one form should have identical inputs from another, plus a few of its own.
81 82 83 84 85 86 87 88 |
# File 'lib/brut/front_end/forms/input_declarations.rb', line 81 def inputs_from(other_class) if !other_class.respond_to?(:input_definitions) raise ArgumentError,"#{other_class} does not respond to #input_definitions - you cannot copy inputs from it" end other_class.input_definitions.each do |_name,input_definition| self.add_input_definition(input_definition) end end |
#radio_button_group(name, attributes = {}) ⇒ Object
Declares a radio button group, which will manifest as one or more <input type="radio"> tags that all use the same
value for their name attribute. Unlike input or select, this method is declaring one or more actual
input tags.
Note that this is not where you would define the possible values for the group. That is done in Components::Inputs::RadioButton.
45 46 47 48 49 |
# File 'lib/brut/front_end/forms/input_declarations.rb', line 45 def (name,attributes={}) self.add_input_definition( Brut::FrontEnd::Forms::RadioButtonGroupInputDefinition.new(**(attributes.merge(name: name))) ) end |
#select(name, attributes = {}) ⇒ Object
Declares a select for this form, to be modeled via an HTML <SELECT> tag. Note that this will not define the values that appear
in the select. That is done when the select is rendered, which you might do with a
Components::Inputs::Select
30 31 32 33 34 |
# File 'lib/brut/front_end/forms/input_declarations.rb', line 30 def select(name,attributes={}) self.add_input_definition( Brut::FrontEnd::Forms::SelectInputDefinition.new(**(attributes.merge(name: name))) ) end |