Class: RailsAdmin::FormBuilder
- Inherits:
-
ActionView::Helpers::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- RailsAdmin::FormBuilder
- Defined in:
- app/helpers/rails_admin/form_builder.rb
Instance Method Summary collapse
- #errors_for(field) ⇒ Object
- #field_for(field) ⇒ Object
- #field_wrapper_for(field) ⇒ Object
- #fieldset_for(fieldset) ⇒ Object
- #help_for(field) ⇒ Object
- #input_for(field) ⇒ Object
- #render(action) ⇒ Object
Instance Method Details
#errors_for(field) ⇒ Object
36 37 38 |
# File 'app/helpers/rails_admin/form_builder.rb', line 36 def errors_for field field.errors.present? ? @template.content_tag(:span, "#{field.label} #{field.errors.first}", :class => 'help-inline') : '' end |
#field_for(field) ⇒ Object
44 45 46 47 48 49 50 |
# File 'app/helpers/rails_admin/form_builder.rb', line 44 def field_for field if field.read_only field.pretty_value.to_s.html_safe else field.render.html_safe end end |
#field_wrapper_for(field) ⇒ Object
21 22 23 24 25 26 |
# File 'app/helpers/rails_admin/form_builder.rb', line 21 def field_wrapper_for field @template.content_tag(:div, :class => "clearfix field #{'error' if field.errors.present?}", :id => field.dom_id + '_field') do label(field.method_name, field.label) + input_for(field) end end |
#fieldset_for(fieldset) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'app/helpers/rails_admin/form_builder.rb', line 12 def fieldset_for fieldset if (fields = fieldset.fields.map{ |f| f.with(:form => self, :object => @object, :view => @template) }.select(&:visible?)).length > 0 @template.content_tag :fieldset do @template.content_tag(:legend, fieldset.label.html_safe + (fieldset.help.present? ? @template.content_tag(:small, fieldset.help) : '')) + fields.map{ |field| field_wrapper_for(field) }.join.html_safe end end end |
#help_for(field) ⇒ Object
40 41 42 |
# File 'app/helpers/rails_admin/form_builder.rb', line 40 def help_for field field.help.present? ? @template.content_tag(:span, field.help, :class => 'help-block') : '' end |
#input_for(field) ⇒ Object
28 29 30 31 32 33 34 |
# File 'app/helpers/rails_admin/form_builder.rb', line 28 def input_for field @template.content_tag(:div, :class => 'input') do field_for(field) + errors_for(field) + help_for(field) end end |
#render(action) ⇒ Object
5 6 7 8 9 10 |
# File 'app/helpers/rails_admin/form_builder.rb', line 5 def render action @template.instance_variable_get(:@model_config).send(action).with(:form => self, :object => @object, :view => @template).visible_groups.map do |fieldset| fieldset_for fieldset end.join.html_safe + @template.render(:partial => 'submit_buttons') end |