Module: DohRails::FormHelpers
- Defined in:
- lib/doh/rails/form_helpers.rb
Class Method Summary collapse
Instance Method Summary collapse
- #doh_checkbox(options) ⇒ Object
- #doh_field(type, options) ⇒ Object
- #doh_hidden_field(options) ⇒ Object
-
#doh_select(select_array, options = {}) ⇒ Object
kjmtodo modify to set default value based on model / field name.
- #doh_text_field(options) ⇒ Object
Class Method Details
.get_id(options) ⇒ Object
12 13 14 |
# File 'lib/doh/rails/form_helpers.rb', line 12 def self.get_id() [:name] ? [:name] : "obj_#{.hash}" end |
.get_label_html(options) ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/doh/rails/form_helpers.rb', line 4 def self.get_label_html() if .key?(:label) label_html = "<label for='#{DohRails::FormHelpers::get_id()}'>#{[:label]}</label>" .delete(:label) end return label_html end |
.option_str(options) ⇒ Object
16 17 18 |
# File 'lib/doh/rails/form_helpers.rb', line 16 def self.option_str() .to_a.collect{|key, value| "#{key}='#{value}'"}.join(' ') end |
Instance Method Details
#doh_checkbox(options) ⇒ Object
33 34 35 |
# File 'lib/doh/rails/form_helpers.rb', line 33 def doh_checkbox() doh_field('checkbox', ) end |
#doh_field(type, options) ⇒ Object
20 21 22 23 |
# File 'lib/doh/rails/form_helpers.rb', line 20 def doh_field(type, ) label_html = DohRails::FormHelpers::get_label_html() "#{label_html}<input id='#{DohRails::FormHelpers::get_id()}' type='#{type}' #{DohRails::FormHelpers::option_str()}" end |
#doh_hidden_field(options) ⇒ Object
29 30 31 |
# File 'lib/doh/rails/form_helpers.rb', line 29 def doh_hidden_field() doh_field('hidden', ) end |
#doh_select(select_array, options = {}) ⇒ Object
kjmtodo modify to set default value based on model / field name
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/doh/rails/form_helpers.rb', line 38 def doh_select(select_array, = {}) label_html = DohRails::FormHelpers::get_label_html() result = '' result += label_html result += "<select id='#{DohRails::FormHelpers::get_id()}' #{DohRails::FormHelpers::option_str()}>\n" select_list = select_array.collect do |elem| "<option value=\"#{elem[0]}\">#{elem[1]}</option>" end result += select_list.join("\n") result += "</select>" result end |
#doh_text_field(options) ⇒ Object
25 26 27 |
# File 'lib/doh/rails/form_helpers.rb', line 25 def doh_text_field() doh_field('text', ) end |