| Class | ApplicationHelper::NoosferoFormBuilder |
| In: |
app/helpers/application_helper.rb
|
| Parent: | ActionView::Helpers::FormBuilder |
Should be on the forms_helper file but when its there the translation of labels doesn‘t work
# File app/helpers/application_helper.rb, line 597
597: def self.output_field(text, field_html, field_id = nil)
598: # try to guess an id if none given
599: if field_id.nil?
600: field_html =~ /id=['"]([^'"]*)['"]/
601: field_id = $1
602: end
603: field_html =~ /type=['"]([^'"]*)['"]/
604: field_html =~ /<(\w*)/ unless $1
605: field_type = $1
606: field_class = 'formfield type-' + field_type if field_type
607:
608: label_html = content_tag('label', gettext(text), :class => 'formlabel', :for => field_id)
609: control_html = content_tag('div', field_html, :class => field_class )
610:
611: content_tag('div', label_html + control_html, :class => 'formfieldline' )
612: end
Create a formatable radio collection Tha values parameter is a array of [value, label] arrays like this:
The option :size will set how many radios will be showed in each line Example: use :size => 3 as option if you want 3 radios by line
# File app/helpers/application_helper.rb, line 636
636: def radio_group( object_name, method, values, options = {} )
637: line_size = options[:size] || 0
638: line_item = 0
639: html = "\n"
640: values.each { |val, h_val|
641: id = object_name.to_s() +'_'+ method.to_s() +'_'+ val.to_s()
642: # Não está apresentando o sexo selecionado ao revisitar
643: # http://localhost:3000/myprofile/manuel/profile_editor/edit :-(
644: html += self.class.content_tag( 'span',
645: @template.radio_button( object_name, method, val,
646: :id => id, :object => @object ) +
647: self.class.content_tag( 'label', h_val, :for => id ),
648: :class => 'lineitem' + (line_item+=1).to_s() ) +"\n"
649: if line_item == line_size
650: line_item = 0
651: html += "<br />\n"
652: end
653: }
654: html += "<br />\n" if line_size == 0 || ( values.size % line_size ) > 0
655: column = object.class.columns_hash[method.to_s]
656: text =
657: ( column ?
658: column.human_name :
659: _(method.to_s.humanize)
660: )
661: label_html = self.class.content_tag 'label', text,
662: :class => 'formlabel'
663: control_html = self.class.content_tag 'div', html,
664: :class => 'formfield type-radio '+
665: 'fieldgroup linesize'+line_size.to_s()
666:
667: self.class.content_tag 'div', label_html + control_html,
668: :class => 'formfieldline'
669: end