Module: Workbench::AutoselectHelper
- Defined in:
- app/helpers/workbench/autoselect_helper.rb
Instance Method Summary collapse
-
#autoselect_field(url:, param:, method:, object: nil, tag_id: nil, current: nil, current_label: nil, placeholder: nil, disabled: false, level_delay: nil, new_record_component: nil, preferences_options_component: nil) ⇒ Object
Renders the mount point for the Vue
AutoselectFieldinitializer (app/javascript/vue/initializers/Autoselect/). -
#autoselect_label_for(record) ⇒ String?
The HTML label a model renders in the autoselect dropdown.
Instance Method Details
#autoselect_field(url:, param:, method:, object: nil, tag_id: nil, current: nil, current_label: nil, placeholder: nil, disabled: false, level_delay: nil, new_record_component: nil, preferences_options_component: nil) ⇒ Object
Renders the mount point for the Vue AutoselectField initializer
(app/javascript/vue/initializers/Autoselect/). The element is inert until
the initializer picks it up on turbolinks:load.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/helpers/workbench/autoselect_helper.rb', line 27 def autoselect_field( url:, param:, method:, object: nil, tag_id: nil, current: nil, current_label: nil, placeholder: nil, disabled: false, level_delay: nil, new_record_component: nil, preferences_options_component: nil ) content_tag(:div, '', data: { 'autoselect' => true, 'autoselect-url' => url, 'autoselect-param' => param, 'autoselect-field-object' => object, 'autoselect-field-property' => method, 'autoselect-id' => tag_id, 'autoselect-placeholder' => placeholder, 'autoselect-disabled' => disabled, 'autoselect-level-delay' => level_delay, 'autoselect-current-value' => current&.id, 'autoselect-current-label' => current_label || autoselect_label_for(current), 'autoselect-new-record-component' => new_record_component, 'autoselect-preferences-options-component' => }) end |
#autoselect_label_for(record) ⇒ String?
Returns the HTML label a model renders in the autoselect dropdown.
60 61 62 63 64 65 66 |
# File 'app/helpers/workbench/autoselect_helper.rb', line 60 def autoselect_label_for(record) return nil if record.nil? tag_method = "#{record.class.base_class.name.underscore}_autoselect_tag" respond_to?(tag_method) ? send(tag_method, record) : label_for(record) end |