Sha256: a8e8f5d09901240e1a630416a3d46387f8a62820fafbb35f9057e84d58b76982

Contents?: true

Size: 1.17 KB

Versions: 13

Compression:

Stored size: 1.17 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)
      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}]", '', id: "hidden_#{mm}_#{ref_name}_#{bhf_primary_key}")
      html = html+' '+check_box_tag("#{mm}[#{ref_name}][#{bhf_primary_key}]", bhf_primary_key, checked)
      html = html+' '+label_tag("#{mm}_#{ref_name}_#{bhf_primary_key}", obj.to_bhf_s) unless hide_label
      
      html
    end

  end
end  

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
bhf-0.9.6 lib/bhf/action_view/form_builder.rb
bhf-0.9.5 lib/bhf/action_view/form_builder.rb
bhf-0.9.4 lib/bhf/action_view/form_builder.rb
bhf-0.9.3 lib/bhf/action_view/form_builder.rb
bhf-0.9.2 lib/bhf/action_view/form_builder.rb
bhf-0.9.1 lib/bhf/action_view/form_builder.rb
bhf-0.9.0 lib/bhf/action_view/form_builder.rb
bhf-0.8.7 lib/bhf/action_view/form_builder.rb
bhf-0.8.6 lib/bhf/action_view/form_builder.rb
bhf-0.8.5 lib/bhf/action_view/form_builder.rb
bhf-0.8.4 lib/bhf/action_view/form_builder.rb
bhf-0.8.3 lib/bhf/action_view/form_builder.rb
bhf-0.8.2 lib/bhf/action_view/form_builder.rb