Class: MultiValueWithElementsInput

Inherits:
SimpleForm::Inputs::CollectionInput
  • Object
show all
Defined in:
app/inputs/multi_value_with_elements_input.rb

Overview

Render Something Like This

<div class=“control-group multi_value_with_elements optional foo_bar”>

<span class="control-label">
  <label class="string multi_value_with_elements optional input-xlarge">Baz</label>
  <label class="string multi_value_with_elements optional input-xlarge">Bong</label>
</span>
<div class="controls">
  <ul class="listing">
    <li class="field-wrapper">
      <fieldset class="composite-input">
        <input aria-labelledby="foo_bar_baz_label" class="foo_bar_baz multi-text-field input-xlarge" name="foo[bar][][baz]" size="30" type="text" value="baz1" />
        <input aria-labelledby="foo_bar_bong_label" class="foo_bar_bong multi-text-field input-xlarge" name="foo[bar][][bong]" size="30" type="text" value="bong1" />
      </fieldset>
    </li>
    <li class="field-wrapper">
      <fieldset class="composite-input">
        <input aria-labelledby="foo_bar_baz_label" class="foo_bar_baz multi-text-field input-xlarge" name="foo[bar][][baz]" size="30" type="text" value="baz2" />
        <input aria-labelledby="foo_bar_bong_label" class="foo_bar_bong multi-text-field input-xlarge" name="foo[bar][][bong]" size="30" type="text" value="bong2" />
      </fieldset>
    </li>
    <li class="field-wrapper">
      <fieldset class="composite-input">
        <input aria-labelledby="foo_bar_baz_label" class="foo_bar_baz multi-text-field input-xlarge" name="foo[bar][][baz]" size="30" type="text" value="" />
        <input aria-labelledby="foo_bar_bong_label" class="foo_bar_bong multi-text-field input-xlarge" name="foo[bar][][bong]" size="30" type="text" value="" />
      </fieldset>
    </li>
  </ul>
</div>

</div>

Instance Method Summary collapse

Instance Method Details

#inputObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/inputs/multi_value_with_elements_input.rb', line 35

def input
  input_html_classes.unshift("string")
  input_html_options[:type] ||= 'text'
  input_html_options[:name] ||= "#{object_name}[#{attribute_name}][]"
  markup = "\n\n  <ul class=\"listing\">\n  HTML\n\n  collection.each_with_index do |value, index|\n    if value.to_s.present?\n      markup << field_wrapper_for(value, index)\n    end\n  end\n\n  markup << field_wrapper_for('', nil)\n  markup << '</ul>'\nend\n"

#labelObject

NOTE: There is a one to many relationship between the label and the input elements. Because of this we can’t use the “for” attribute on the label point to the “id” of the input. Instead we use the “aria-labelledby” attribute on the input to point to the “id” on the label.

It would be better to use @builder construct the element but the proper syntax escapes me.



62
63
64
65
66
# File 'app/inputs/multi_value_with_elements_input.rb', line 62

def label
  options[:elements].each_with_object('') {|element_name, html|
    html << element_label(element_name)
  }
end