Module: Wallaby::FormHelper

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

Overview

Form helper

Instance Method Summary collapse

Instance Method Details

#form_type_partial_render(options = {}, locals = {}, &block) ⇒ String

Returns rendered type partial for a form.

Parameters:

  • options (Hash, String) (defaults to: {})
  • locals (Hash) (defaults to: {})

    local variables for the partial

Returns:

  • (String)

    rendered type partial for a form



7
8
9
# File 'lib/helpers/wallaby/form_helper.rb', line 7

def form_type_partial_render(options = {}, locals = {}, &block)
  PartialRenderer.render_form self, options, locals, &block
end

#hint_of(metadata) ⇒ String?

To fetch the hints from the following keys:

  • hints.#type_html

  • hints.#type

Parameters:

  • metadata (Hash)

Returns:

  • (String, nil)

    HTML



53
54
55
56
57
58
59
60
61
# File 'lib/helpers/wallaby/form_helper.rb', line 53

def hint_of()
  type = [:type]
  hint = [:hint]
  # @see http://guides.rubyonrails.org/i18n.html#using-safe-html-translations
  hint ||= type && t("hints.#{type}_html", default: '').presence
  hint ||= type && t("hints.#{type}", default: '').presence
  return unless hint
   :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:



37
38
39
40
41
42
43
44
45
46
# File 'lib/helpers/wallaby/form_helper.rb', line 37

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:



19
20
21
22
23
24
25
26
# File 'lib/helpers/wallaby/form_helper.rb', line 19

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