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) ⇒ Object

Parameters:

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

    local variables for the partial



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

def form_type_partial_render(options = {}, locals = {}, &block)
  PartialRenderer.render_form self, options, locals, &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')
  • select_options (Hash) (defaults to: {})

Returns:

  • (String)

    HTML

See Also:

  • Wallaby::FormHelper.app/assets/javascripts/wallaby/auto_selectapp/assets/javascripts/wallaby/auto_select.js


34
35
36
37
38
39
40
41
42
43
# File 'lib/helpers/wallaby/form_helper.rb', line 34

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') ⇒ Object

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

See Also:

  • Wallaby::FormHelper.app/assets/javascripts/wallaby/auto_selectapp/assets/javascripts/wallaby/auto_select.js


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

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