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
-
#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 theirname
attribute. -
#select(name, attributes = {}) ⇒ Object
Declares a select for this form, to be modeled via an HTML
<SELECT>
tag.
Instance Method Details
#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.
71 72 73 74 75 76 77 78 |
# File 'lib/brut/front_end/forms/input_declarations.rb', line 71 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.
35 36 37 38 39 |
# File 'lib/brut/front_end/forms/input_declarations.rb', line 35 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
20 21 22 23 24 |
# File 'lib/brut/front_end/forms/input_declarations.rb', line 20 def select(name,attributes={}) self.add_input_definition( Brut::FrontEnd::Forms::SelectInputDefinition.new(**(attributes.merge(name: name))) ) end |