Sha256: ce818a6a854869e59326ea8f4dfeee9a3bcf4aedf4e0e5aa88346bc0553c3c1f

Contents?: true

Size: 1.23 KB

Versions: 7

Compression:

Stored size: 1.23 KB

Contents

module Bhf::ActionView
  class FormBuilder < ActionView::Helpers::FormBuilder
    include ActionView::Helpers::FormTagHelper

    def error_label(name, message)
      label name, "#{object.class.human_attribute_name(name)} #{message}"
    end

    def field_errors(field)
      object.errors[field.to_sym]
    end

    def field_has_errors?(field)
      field_errors(field).any?
    end

    def many_to_many_check_box(obj, ref_name, params, hide_label = false, checked = false, bhf_primary_key = nil, extra_html_attrs = {})
      mm = :has_and_belongs_to_many
      bhf_primary_key ||= obj.send(obj.class.bhf_primary_key).to_s
      unless checked
        checked = if params[mm] && params[mm][ref_name]
          params[mm][ref_name][bhf_primary_key] != ''
        else
          object.send(ref_name).include?(obj)
        end
      end
      
      html = hidden_field_tag("#{mm}[#{ref_name}][#{bhf_primary_key}]", '', extra_html_attrs.merge(id: "hidden_#{mm}_#{ref_name}_#{bhf_primary_key}"))
      html = html+' '+check_box_tag("#{mm}[#{ref_name}][#{bhf_primary_key}]", bhf_primary_key, checked, extra_html_attrs)
      html = html+' '+label_tag("#{mm}_#{ref_name}_#{bhf_primary_key}", obj.to_bhf_s) unless hide_label
      
      html
    end

  end
end  

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
bhf-0.10.12 lib/bhf/action_view/form_builder.rb
bhf-0.10.11 lib/bhf/action_view/form_builder.rb
bhf-0.10.10 lib/bhf/action_view/form_builder.rb
bhf-0.10.9 lib/bhf/action_view/form_builder.rb
bhf-0.9.9 lib/bhf/action_view/form_builder.rb
bhf-0.9.8 lib/bhf/action_view/form_builder.rb
bhf-0.9.7 lib/bhf/action_view/form_builder.rb