Sha256: c1600ffffc831c93fc77646e7822a02f1625e220609d723892beac694f7b4d32

Contents?: true

Size: 1.88 KB

Versions: 2

Compression:

Stored size: 1.88 KB

Contents

module Agilibox::FormHelper
  include Agilibox::I18nHelper

  # Hidden submit to be the default triggered on <enter> keypress on a form
  def form_hidden_submit
    tag(:input, type: "submit", class: "hidden-submit")
  end

  def form_buttons(opts = {})
    back_url = opts[:back_url]
    back_url = url_for(:back).html_safe if back_url.nil?
    back_url = URI(back_url).path       if back_url.to_s.include?("://")

    if opts[:obj].present?
      if opts[:obj].new_record?
        submit_action = :create
      else
        submit_action = :update
      end
    else
      submit_action = :save
    end

    tag.div(class: "actions form-actions") do
      submit = tag.button(type: :submit, class: "btn btn-sm btn-success form-submit") do
        tag.span(class: "fa fa-save") + " " + ta(submit_action)
      end

      cancel = tag.a(href: back_url, class: "btn btn-primary btn-sm form-cancel") do
        tag.span(class: "fa fa-times") + " " + ta(:cancel)
      end

      cancel = "" if back_url == false

      submit + cancel
    end
  end

  def horizontal_form_for(obj, opts = {}, &block)
    opts = {
      :wrapper => "horizontal_form",
      :html => {
        :class => "form-horizontal",
      },
    }.deep_merge(opts)

    simple_form_for(obj, opts, &block)
  end

  def search_form(action: request.fullpath)
    render "agilibox/search/form", action: action
  end

  def checkboxes_dropdown(f, input, collection, label = t("actions.select"))
    render("agilibox/forms/checkboxes_dropdown",
      :f          => f,
      :input      => input,
      :collection => collection,
      :label      => label,
    )
  end

  def hidden_inputs_for_get_form(url, except: [])
    query_values = Addressable::URI.parse(url).query_values.to_h
      .with_indifferent_access
      .except(*except)

    return if query_values.empty?

    query_values.sum { |k, v| tag.input(type: "hidden", name: k, value: v) }
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
agilibox-1.11.0 app/helpers/agilibox/form_helper.rb
agilibox-1.10.5 app/helpers/agilibox/form_helper.rb