Module: Wallaby::FormHelper
- Included in:
- ResourcesHelper
- Defined in:
- lib/helpers/wallaby/form_helper.rb
Overview
Form helper
Instance Method Summary collapse
-
#form_type_partial_render(options = {}, locals = {}, &block) ⇒ String
Rendered type partial for a form.
-
#hint_of(metadata) ⇒ String?
To fetch the hints from the following keys: - hints.#type_html - hints.#type.
-
#polymorphic_options(metadata, wildcard = 'QUERY', select_options = {}) ⇒ String
To generate dropdown options (class => url) for polymorphic class.
-
#remote_url(url, model_class, wildcard = 'QUERY') ⇒ String
To generate remote url for auto select plugin.
Instance Method Details
#form_type_partial_render(options = {}, locals = {}, &block) ⇒ String
Returns rendered type partial for a form.
7 8 9 |
# File 'lib/helpers/wallaby/form_helper.rb', line 7 def form_type_partial_render( = {}, locals = {}, &block) PartialRenderer.render_form self, , locals, &block end |
#hint_of(metadata) ⇒ String?
To fetch the hints from the following keys:
-
hints.#type_html
-
hints.#type
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 content_tag :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).
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/helpers/wallaby/form_helper.rb', line 37 def (, wildcard = 'QUERY', = {}) urls = [:remote_urls] || {} = ([:polymorphic_list] || []).map do |klass| [ klass, klass, { data: { url: remote_url(urls[klass], klass, wildcard) } } ] end , end |
#remote_url(url, model_class, wildcard = 'QUERY') ⇒ String
To generate remote url for auto select plugin.
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 |