Class: PredicateTomSelectInput

Inherits:
SimpleForm::Inputs::Base
  • Object
show all
Defined in:
app/inputs/predicate_tom_select_input.rb

Overview

A compound input that renders a predicate dropdown (IN / NOT IN) alongside a
Tom Select multi-select. When the predicate changes the Stimulus controller
rewrites the element's name attribute so the correct scope key
({attr}_in or {attr}_not_in) is submitted with the form.

Usage:
f.input :state, as: :predicate_tom_select,
collection: Customer.states_for_select,
label: 'Status'

Constant Summary collapse

PREDICATES =
[
  ['is any of', 'in'],
  ['is none of', 'not_in']
].freeze

Instance Method Summary collapse

Instance Method Details

#input(_wrapper_options = nil) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/inputs/predicate_tom_select_input.rb', line 17

def input(_wrapper_options = nil)
  template.(
    :div,
    class: 'input-group flex-nowrap w-100',
    data: {
      controller: 'predicate-select',
      'predicate-select-base-name-value' => base_name
    }
  ) do
    template.concat predicate_dropdown
    template.concat values_select
  end
end