Method: MuckEngine::FormBuilder#render_field_template
- Defined in:
- lib/muck-engine/form_builder.rb
#render_field_template(name, field, options) ⇒ Object
Options to pass to render_field_template through the ‘options’ argument. pre_html html content to insert at the beginning of the container extra_html html content to insert at the end of the container tip Text for a popup text tip. tip_title Title for popup text tip tip_key The id of the div that contains the tip text. tip_position Position for tip text. Valid values are ‘top’, ‘right’, ‘bottom’, ‘left’. Default is ‘right’ wrapper_id Alternate id for the container. Each field is typically wrapper in a div. This is the id of that div. wrapper_class Css class for the container. All containers have the class form-row. This value will be in addition to that class. label_class Css class for the label hide_label Prevents a label from being output hide_required Do not show ‘required’ label even though field is required hide_control_error Hide errors that show up next to the field required_text_mark By default ‘(required)’ is used to show required fields. Override this by setting required_text_mark to something else - ie ‘*’
Alternatively override 'muck.engine.required_text_mark' in your app's en.yml or the appropriate localization file. You can also
specify a value in global_config.yml with required_text_mark: *
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/muck-engine/form_builder.rb', line 37 def render_field_template(name, field, ) tippable = ![:tip].nil? # used by country, state and other selects to specify a different id field_id = [:field_id] = { :pre_html => .delete(:pre_html), :after_label_html => .delete(:after_label_html), :extra_html => .delete(:extra_html), :tip => .delete(:tip), :tip_title => .delete(:tip_title), :tip_key => .delete(:tip_key), :tip_position => .delete(:tip_position) || 'right', :wrapper_id => .delete(:wrapper_id), :wrapper_class => .delete(:wrapper_class), :hide_required => .delete(:hide_required), :hide_control_error => .delete(:hide_control_error), :css_class => .delete(:css_class) } # TODO css_class does not appear to be used. Can just use the standard :class in html options to set the class is_checkbox = false is_checkbox = true if %w(check_box).include?(name) required_text_mark = .delete(:required_text_mark) type = .delete(:type) type ||= :tippable if tippable label_class = '' label_class << "checkbox-label" if is_checkbox label_class << " #{options.delete(:label_class)}" if ![:label_class].nil? if label_class.blank? = {} else = { :class => label_class } end if [:hide_required] required = false label_text = [:label] else required = required_field?(field) label_text = ([:label] || field.to_s.camelize) label_text = label_text + required_mark(field, required_text_mark) if required end label_name = .delete(:label) [:class] ||= '' [:class] << add_space_to_css() + 'tip-field' if tippable [:class] << add_space_to_css() + "required-value" if required if type == :choose_menu [:label_class] = 'desc' end if .delete(:hide_label) label_element = '' else label_element = label(field, label_text.html_safe, ) end locals = { :field_element => yield, :field_name => field_id || field_name(field), :label_name => .delete(:required_label) || label_name || '', :label_element => label_element, :is_checkbox => is_checkbox, :required => required }.merge() if object.nil? locals[:value] = '' locals[:id] = '' else locals[:value] = object.send(field) locals[:id] = object.id end if has_errors_on?(field) locals.merge!(:error => (field, )) end @template.capture do if type == :tippable @template.render :partial => 'forms/field_with_tips', :locals => locals elsif type == :choose_menu @template.render :partial => 'forms/menu_field', :locals => locals elsif type == :color_picker @template.render :partial => 'forms/color_picker_field', :locals => locals elsif type == :default @template.render :partial => 'forms/default', :locals => locals else @template.render :partial => 'forms/field', :locals => locals end end end |