app/helpers/misc_helper.rb
# Returns the HTML text for an Option group converted to a bunch of buttons, each
# one storing the key value for the select into an hidden field having the name specified.
#
# An additional display-only field for visual aid of the selection can be turned
# on or off using show_additional_display_label.
#
Returns the HTML text for an Option group converted to a bunch of buttons, each
one storing the key value for the select into an hidden field having the name specified.

An additional display-only field for visual aid of the selection can be turned
on or off using show_additional_display_label.
Returns the HTML text for an Option group converted to a bunch of buttons each one storing the key value for the select into an hidden field having the name specified . An additional display - only field for visual aid of the selection can be turned on or off using show_additional_display_label .
def button_option_group( field_name, default_value, array_of_labels_and_keys_couples,
                           show_additional_display_label = false )
    rendered_html = hidden_field_tag( field_name, default_value ) + "\r\n".html_safe
    display_field_name = field_name.to_s.gsub( '_id', '_label' )
    rendered_html += "<div class=\"btn-group btn-group-sm\" role=\"group\">\r\n".html_safe
    array_of_labels_and_keys_couples.each do |label, key|
      rendered_html += link_to(
        content_tag( :span, get_image_tag_for( field_name, key, label ) ),
        "##{field_name}",
        {
          id: "btn_#{field_name}",
          class: 'btn btn-default',
          role: 'button',
          'aria-describedby' => display_field_name,
          'onclick' => "$('##{field_name}').val(#{key}); $('##{display_field_name}').text('#{label}')",
          'data-turbolinks'=>'false',
          'data-toggle' => 'tooltip',
          title: label
        }
      )
      rendered_html += "\r\n".html_safe
    end
    rendered_html += "</div>\r\n".html_safe
    if show_additional_display_label
      default_label_text = array_of_labels_and_keys_couples.kind_of?(Array) && default_value && array_of_labels_and_keys_couples[default_value] ? array_of_labels_and_keys_couples[default_value].first : ''
      rendered_html += content_tag( :span, default_label_text, id: display_field_name, class: "help-block" )
    end
    rendered_html.html_safe
  end
def button_option_group ( field_name , default_value , array_of_labels_and_keys_couples , show_additional_display_label = false ) rendered_html = hidden_field_tag ( field_name , default_value ) + "\r\n" . html_safe display_field_name = field_name . to_s . gsub ( '_id' , '_label' ) rendered_html += "<div class=\"btn-group btn-group-sm\" role=\"group\">\r\n" . html_safe array_of_labels_and_keys_couples . each do | label , key | rendered_html += link_to ( content_tag ( :span , get_image_tag_for ( field_name , key , label ) ) , "##{field_name}" , { id : "btn_#{field_name}" , class : 'btn btn-default' , role : 'button' , 'aria-describedby' => display_field_name , 'onclick' => "$('##{field_name}').val(#{key}); $('##{display_field_name}').text('#{label}')" , 'data-turbolinks' => 'false' , 'data-toggle' => 'tooltip' , title : label } ) rendered_html += "\r\n" . html_safe end rendered_html += "</div>\r\n" . html_safe if show_additional_display_label default_label_text = array_of_labels_and_keys_couples . kind_of? ( Array ) && default_value && array_of_labels_and_keys_couples [ default_value ] ? array_of_labels_and_keys_couples [ default_value ] . first : '' rendered_html += content_tag ( :span , default_label_text , id : display_field_name , class : "help-block" ) end rendered_html . html_safe end
Returns the HTML text for an Option group converted to a bunch of buttons, each
one storing the key value for the select into an hidden field having the name specified.
Returns the HTML text for an Option group converted to a bunch of buttons each one storing the key value for the select into an hidden field having the name specified .
# For each defined option couple:
field_name
<not_specific>
default_value
<not_specific>
array_of_labels_and_keys_couples
<not_specific>
show_additional_display_label
<not_specific>