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 }

Parameters:

  • metadata (Hash)

Returns:

  • (String, nil)

    HTML



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).

Parameters:

  • metadata (Hash)
  • wildcard (String) (defaults to: 'QUERY')

    wildcard to be used in the URL

  • select_options (Hash) (defaults to: {})

Returns:

  • (String)

    options HTML

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.

Parameters:

  • url (String, nil)

    if URL is nil, it will fall back to default remote URL

  • model_class (Class)
  • wildcard (String) (defaults to: 'QUERY')

    wildcard that auto_select uses to replace with the typed keyword

Returns:

  • (String)

    URL for autocomplete

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