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”>


  
  

</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 = <<-HTML


  <ul class="listing">
  HTML

  collection.each_with_index do |value, index|
    if value.to_s.present?
      markup << field_wrapper_for(value, index)
    end
  end

  markup << field_wrapper_for('', nil)
  markup << '</ul>'
end

#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