Sha256: e5856a47bba0c9f414e11243df4af0b1e372de13e97e508db5bc806491346a76

Contents?: true

Size: 1.1 KB

Versions: 4

Compression:

Stored size: 1.1 KB

Contents

module Headmin
  module FormHelper
    def form_field_valid?(form, name)
      !form.object.errors.has_key?(name)
    end

    def form_field_validation_id(form, name)
      [form.object_name, name.to_s, 'validation'].join('_').parameterize.underscore
    end

    def form_field_validation_class(form, name)
      return nil if request.get?
      form.object.errors.has_key?(name) ? 'is-invalid' : 'is-valid'
    end

    # Outputs currently present query parameters as hidden fields for a given form
    #
    # https://example.com/products?amount=1&type[]=food&type[]=beverage
    #
    # <%= form.hidden_input :amount, value: 1 %>
    # <%= form.hidden_input :'type[]', value: 'food' %>
    # <%= form.hidden_input :'type[]', value: 'beverage' %>
    def query_parameter_fields(form)
      test = request.query_parameters.map do |name, value|
        if value.is_a?(Array)
          value.map do |value_element|
            form.hidden_field "#{name}[]", value: value_element
          end.join
        else
          form.hidden_field name, value: value
        end
      end
      test.join.html_safe
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
headmin-0.2.9 app/helpers/headmin/form_helper.rb
headmin-0.2.8 app/helpers/headmin/form_helper.rb
headmin-0.2.7 app/helpers/headmin/form_helper.rb
headmin-0.2.6 app/helpers/headmin/form_helper.rb