Sha256: ecc1a0becfcfe74a8b569ec740075979bffa324fc779c00cfb10dae502c9f59f

Contents?: true

Size: 1.75 KB

Versions: 19

Compression:

Stored size: 1.75 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_or_has_many_check_box(mm, obj, ref_name, params, hide_label = false, checked = false, bhf_primary_key = nil, extra_html_attrs = {})
      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

    def many_to_many_check_box(obj, ref_name, params, hide_label = false, checked = false, bhf_primary_key = nil, extra_html_attrs = {})
      many_to_many_or_has_many_check_box(:has_and_belongs_to_many, obj, ref_name, params, hide_label, checked, bhf_primary_key, extra_html_attrs)
    end

    def has_many_check_box(obj, ref_name, params, hide_label = false, checked = false, bhf_primary_key = nil, extra_html_attrs = {})
      many_to_many_or_has_many_check_box(:has_many, obj, ref_name, params, hide_label, checked, bhf_primary_key, extra_html_attrs)
    end

  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
bhf-1.0.0.beta16 lib/bhf/action_view/form_builder.rb
bhf-1.0.0.beta15 lib/bhf/action_view/form_builder.rb
bhf-1.0.0.beta14 lib/bhf/action_view/form_builder.rb
bhf-1.0.0.beta13 lib/bhf/action_view/form_builder.rb
bhf-1.0.0.beta12 lib/bhf/action_view/form_builder.rb
bhf-1.0.0.beta11 lib/bhf/action_view/form_builder.rb
bhf-1.0.0.beta10 lib/bhf/action_view/form_builder.rb
bhf-1.0.0.beta9 lib/bhf/action_view/form_builder.rb
bhf-1.0.0.beta8 lib/bhf/action_view/form_builder.rb
bhf-1.0.0.beta7 lib/bhf/action_view/form_builder.rb
bhf-1.0.0.beta6 lib/bhf/action_view/form_builder.rb
bhf-1.0.0.beta5 lib/bhf/action_view/form_builder.rb
bhf-1.0.0.beta4 lib/bhf/action_view/form_builder.rb
bhf-1.0.0.beta3 lib/bhf/action_view/form_builder.rb
bhf-1.0.0.beta2 lib/bhf/action_view/form_builder.rb
bhf-1.0.0.beta1 lib/bhf/action_view/form_builder.rb
bhf-0.10.17 lib/bhf/action_view/form_builder.rb
bhf-0.10.16 lib/bhf/action_view/form_builder.rb
bhf-0.10.15 lib/bhf/action_view/form_builder.rb