Sha256: ebac954e67eb2285df7f06a90bbd7fc203811d49bb93f5d8a3b0e1a55cdad03f

Contents?: true

Size: 983 Bytes

Versions: 27

Compression:

Stored size: 983 Bytes

Contents

module Bhf
  module Form

    class Builder < 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)
        mm = :has_and_belongs_to_many
        checked = if params[mm] && params[mm][ref_name]
          params[mm][ref_name][obj.id.to_s] != ''
        else
          object.send(ref_name).include?(obj)
        end

        hidden_field_tag("#{mm}[#{ref_name}][#{obj.id}]", '', :id => "hidden_has_and_belongs_to_many_#{ref_name}_#{obj.id}")+' '+
        check_box_tag("#{mm}[#{ref_name}][#{obj.id}]", obj.id, checked)+' '+
        label_tag("#{mm}_#{ref_name}_#{obj.id}", obj.to_bhf_s)
      end

    end

  end  
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
bhf-0.4.2.2 lib/bhf/form.rb
bhf-0.4.2.1 lib/bhf/form.rb
bhf-0.4.2 lib/bhf/form.rb
bhf-0.4.1 lib/bhf/form.rb
bhf-0.4.0 lib/bhf/form.rb
bhf-0.3.11 lib/bhf/form.rb
bhf-0.3.10 lib/bhf/form.rb
bhf-0.3.9 lib/bhf/form.rb
bhf-0.3.8 lib/bhf/form.rb
bhf-0.3.7 lib/bhf/form.rb
bhf-0.3.6.4 lib/bhf/form.rb
bhf-0.3.6.3 lib/bhf/form.rb
bhf-0.3.6.2 lib/bhf/form.rb
bhf-0.3.6.1 lib/bhf/form.rb
bhf-0.3.5 lib/bhf/form.rb
bhf-0.3.4 lib/bhf/form.rb
bhf-0.3.3 lib/bhf/form.rb
bhf-0.2.2 lib/bhf/form.rb
bhf-0.2.1 lib/bhf/form.rb
bhf-0.2.0 lib/bhf/form.rb