Module: HakumiComponents::Concerns::SelectionControl

Extended by:
T::Helpers, T::Sig
Includes:
FormField, SelectionControlInterface
Included in:
Autocomplete::Component, HakumiComponents::Cascader::Component, Select::Component, TreeSelect::Component
Defined in:
app/components/hakumi_components/concerns/selection_control.rb

Instance Method Summary collapse

Methods included from FormField

#describedby_ids, #error?, #error_message, #form_field_caption, #form_field_contract, #form_field_errors, #form_field_html_options, #form_field_label, #form_field_name, #form_field_required, #form_field_rules, #form_field_standalone, #form_item_attributes, #form_item_classes, #input_id, #render_caption, #render_error, #render_explain, #render_label, #standalone?

Methods included from FormFieldInterface

#form_field_contract

Instance Method Details

#selection_control_allow_clearObject



44
45
46
# File 'app/components/hakumi_components/concerns/selection_control.rb', line 44

def selection_control_allow_clear
  selection_control_contract.allow_clear
end

#selection_control_contractObject



16
17
18
19
20
21
# File 'app/components/hakumi_components/concerns/selection_control.rb', line 16

def selection_control_contract
  contract = T.let(@selection_control_contract, T.nilable(SelectionControlContract))
  return contract unless contract.nil?

  Kernel.raise "selection_control_contract must be initialized"
end

#selection_control_disabledObject



39
40
41
# File 'app/components/hakumi_components/concerns/selection_control.rb', line 39

def selection_control_disabled
  selection_control_contract.disabled
end

#selection_control_has_value?Boolean

Returns:

  • (Boolean)


49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/components/hakumi_components/concerns/selection_control.rb', line 49

def selection_control_has_value?
  value = selection_control_value
  if value.is_a?(Array)
    return value.any? do |item|
      next false if item.nil? || item == false
      next !item.empty? if item.is_a?(String)

      true
    end
  end

  return false if value.nil? || value == false
  return !value.empty? if value.is_a?(String)

  true
end

#selection_control_placeholderObject



29
30
31
# File 'app/components/hakumi_components/concerns/selection_control.rb', line 29

def selection_control_placeholder
  selection_control_contract.placeholder
end

#selection_control_sizeObject



34
35
36
# File 'app/components/hakumi_components/concerns/selection_control.rb', line 34

def selection_control_size
  selection_control_contract.size
end

#selection_control_valueObject



24
25
26
# File 'app/components/hakumi_components/concerns/selection_control.rb', line 24

def selection_control_value
  selection_control_contract.value
end