Class: Kiss::Form::SelectField

Inherits:
MultiChoiceField show all
Defined in:
lib/kiss/form/field.rb

Constant Summary

Constants inherited from Field

Field::CURRENCY_SYMBOLS

Instance Method Summary collapse

Methods inherited from MultiChoiceField

#column_layout, #display_to_s, #form=, #has_option_value?, #initialize, #option_pairs, #options_keys, #other_field_html, #validate

Methods inherited from Field

#add_error, #content_tag_html, #debug, #errors_html, #html, #initialize, #input_tag_html, #method_missing, #param, #require_value, #reset, #set_value_to_hash, #set_value_to_object, #tag_html, #tag_start_html, #tip_html, #type, #validate, #value, #value_string, #value_to_s

Constructor Details

This class inherits a constructor from Kiss::Form::MultiChoiceField

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Kiss::Form::Field

Instance Method Details

#element_html(attrs = {}) ⇒ Object



599
600
601
602
603
604
605
606
607
608
609
610
611
612
# File 'lib/kiss/form/field.rb', line 599

def element_html(attrs = {})
  return 'No options' unless @_options.size > 0
  
  @_choose_here ||= 'Choose Here'
  placeholder_html = %Q(<option value="">#{@_choose_here}</option>)
  
  options_html = option_pairs.map do |option_value, option_display|
    option_value_string = value_to_s(option_value)
    selected = (value_string == option_value_string) ? ' selected' : ''
    %Q(<option value="#{option_value_string}"#{selected}>#{display_to_s(option_display)}</option>)
  end.join
  
  ('select', placeholder_html + options_html, attrs) + other_field_html + tip_html(attrs)
end