Module FormsHelper
In: app/helpers/forms_helper.rb

Methods

Protected Class methods

[Source]

     # File app/helpers/forms_helper.rb, line 100
100:   def self.next_id_number
101:     if defined? @@id_num
102:       @@id_num.next!
103:     else
104:       @@id_num = '0'
105:     end
106:   end

Public Instance methods

[Source]

   # File app/helpers/forms_helper.rb, line 3
3:   def generate_form( name, obj, fields={} )
4:     labelled_form_for name, obj do |f|
5:       f.text_field(:name)
6:     end
7:   end

[Source]

    # File app/helpers/forms_helper.rb, line 15
15:   def labelled_check_box( human_name, name, value = "1", checked = false, options = {} )
16:     options[:id] ||= 'checkbox-' + FormsHelper.next_id_number
17:     check_box_tag( name, value, checked, options ) +
18:     content_tag( 'label', human_name, :for => options[:id] )
19:   end

[Source]

    # File app/helpers/forms_helper.rb, line 9
 9:   def labelled_radio_button( human_name, name, value, checked = false, options = {} )
10:     options[:id] ||= 'radio-' + FormsHelper.next_id_number
11:     radio_button_tag( name, value, checked, options ) +
12:     content_tag( 'label', human_name, :for => options[:id] )
13:   end

[Source]

    # File app/helpers/forms_helper.rb, line 27
27:   def labelled_select( human_name, name, value_method, text_method, selected, collection, options={} )
28:     options[:id] ||= 'select-' + FormsHelper.next_id_number
29:     content_tag('label', human_name, :for => options[:id]) +
30:     select_tag( name, options_from_collection_for_select(collection, value_method, text_method, selected), options)
31:   end

[Source]

    # File app/helpers/forms_helper.rb, line 21
21:   def labelled_text_field( human_name, name, value=nil, options={} )
22:     options[:id] ||= 'text-field-' + FormsHelper.next_id_number
23:     content_tag('label', human_name, :for => options[:id]) +
24:     text_field_tag( name, value, options )
25:   end

[Source]

    # File app/helpers/forms_helper.rb, line 57
57:   def select_city( simple=false )
58:     states = State.find(:all, :order => 'name')
59:     
60:     state_id = 'state-' + FormsHelper.next_id_number
61:     city_id = 'city-' + FormsHelper.next_id_number
62:     
63:     if simple
64:       states = [State.new(:name => _('Select the State'))] + states
65:       cities = [City.new(:name => _('Select the City'))]
66: 
67:       html_state =
68:       content_tag( 'div',
69:                    select_tag( 'state',
70:                                options_from_collection_for_select( states, :id, :name, nil),
71:                                :id => state_id ),
72:                    :class => 'select_state_for_origin' )
73:       html_city =
74:       content_tag( 'div',
75:                    select_tag( 'city',
76:                                options_from_collection_for_select( cities, :id, :name, nil),
77:                                :id => city_id ),
78:                    :class => 'select_city_for_origin' )
79:       html_state['<option'] = '<option class="first-option"'
80:       html_city['<option']  = '<option class="first-option"'
81:       html = html_state + html_city
82:     else
83:       states = [State.new(:name => '---')] + states
84:       cities = [City.new(:name => '---')]
85: 
86:       html = 
87:       content_tag( 'div',
88:                    labelled_select( _('State:'), 'state', :id, :name, nil, states, :id => state_id ),
89:                    :class => 'select_state_for_origin' ) +
90:       content_tag( 'div',
91:                    labelled_select( _('City:'), 'city', :id, :name, nil, cities, :id => city_id ),
92:                    :class => 'select_city_for_origin' )
93:     end
94:     
95:     html +
96:     observe_field( state_id, :update => city_id, :function => "new Ajax.Updater(#{city_id.inspect}, #{url_for(:controller => 'search', :action => 'cities').inspect}, {asynchronous:true, evalScripts:true, parameters:'state_id=' + value}); $(#{city_id.inspect}).innerHTML = '<option>#{_('Loading...')}</option>'", :with => 'state_id')
97:   end

[Source]

    # File app/helpers/forms_helper.rb, line 33
33:   def submit_button(type, label, html_options = {})
34:     bt_cancel = html_options[:cancel] ? button(:cancel, _('Cancel'), html_options[:cancel]) : ''
35: 
36:     html_options[:class] = [html_options[:class], 'submit'].compact.join(' ')
37: 
38:     the_class = "button with-text icon-#{type}"
39:     if html_options.has_key?(:class)
40:       the_class << ' ' << html_options[:class]
41:     end
42: 
43:     # FIXME: should be in stylesheet
44:     bt_submit = submit_tag(label, html_options.merge(:style => 'height:28px; cursor:pointer', :class => the_class))
45: 
46:     bt_submit + bt_cancel
47:   end

[Source]

    # File app/helpers/forms_helper.rb, line 49
49:   def text_field_with_local_autocomplete(name, choices, html_options = {})
50:     id = html_options[:id] || name
51: 
52:     text_field_tag(name, '', html_options) +
53:     content_tag('div', '', :id => "autocomplete-for-#{id}", :class => 'auto-complete', :style => 'display: none;') +
54:     javascript_tag('new Autocompleter.Local(%s, %s, %s)' % [ id.to_json, "autocomplete-for-#{id}".to_json, choices.to_json ] )
55:   end

[Validate]