Module: Wallaby::FormHelper

Included in:
ResourcesHelper
Defined in:
lib/helpers/wallaby/form_helper.rb

Overview

Form helper

Instance Method Summary collapse

Instance Method Details

#hint_of(metadata) ⇒ String?

To fetch the hints from the following keys:

  • hints.#{ type }_html

  • hints.#{ type }



45
46
47
48
49
50
51
52
53
# File 'lib/helpers/wallaby/form_helper.rb', line 45

def hint_of()
  type = [:type]
  hint = [:hint]
  # @see http://guides.rubyonrails.org/i18n.html#using-safe-html-translations
  hint ||= type && wt("hints.#{type}_html", default: [:"hints.#{type}", ''])
  return if hint.blank?

   :p, hint, class: 'help-block'
end

#polymorphic_options(metadata, wildcard = 'QUERY', select_options = {}) ⇒ String

To generate dropdown options (class => url) for polymorphic class. This function will pull out remote URLs from ‘metadata` (Class => url).

See Also:

  • auto_select.js
  • ActionView::Helpers::FormOptionsHelper#options_for_select


29
30
31
32
33
34
35
36
37
38
# File 'lib/helpers/wallaby/form_helper.rb', line 29

def polymorphic_options(, wildcard = 'QUERY', select_options = {})
  urls = [:remote_urls] || {}
  options = ([:polymorphic_list] || []).map do |klass|
    [
      klass, klass,
      { data: { url: remote_url(urls[klass], klass, wildcard) } }
    ]
  end
  options_for_select options, select_options
end

#remote_url(url, model_class, wildcard = 'QUERY') ⇒ String

To generate remote URL for auto select plugin.

See Also:



15
16
17
# File 'lib/helpers/wallaby/form_helper.rb', line 15

def remote_url(url, model_class, wildcard = 'QUERY')
  url || index_path(model_class, url_params: { q: wildcard, per: wallaby_controller.try(:page_size) })
end