Class: Primer::Forms::Dsl::CheckBoxInput
- Defined in:
- app/lib/primer/forms/dsl/check_box_input.rb
Overview
:nodoc:
Constant Summary collapse
- DEFAULT_SCHEME =
:boolean
- SCHEMES =
[DEFAULT_SCHEME, :array].freeze
Constants inherited from Input
Input::DEFAULT_INPUT_WIDTH, Input::DEFAULT_SIZE, Input::INPUT_WIDTH_MAPPINGS, Input::INPUT_WIDTH_OPTIONS, Input::SIZE_MAPPINGS, Input::SIZE_OPTIONS, Input::SPACE_DELIMITED_ARIA_ATTRIBUTES
Instance Attribute Summary collapse
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#nested_form_arguments ⇒ Object
readonly
Returns the value of attribute nested_form_arguments.
-
#nested_form_block ⇒ Object
readonly
Returns the value of attribute nested_form_block.
-
#scheme ⇒ Object
readonly
Returns the value of attribute scheme.
-
#unchecked_value ⇒ Object
readonly
Returns the value of attribute unchecked_value.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Attributes inherited from Input
#base_id, #builder, #caption, #form, #form_control, #ids, #input_arguments, #label_arguments, #validation_message
Instance Method Summary collapse
-
#initialize(name:, label:, value: nil, unchecked_value: nil, scheme: DEFAULT_SCHEME, **system_arguments) {|_self| ... } ⇒ CheckBoxInput
constructor
A new instance of CheckBoxInput.
- #nested_form(**system_arguments, &block) ⇒ Object
- #supports_validation? ⇒ Boolean
-
#to_component ⇒ Object
:nocov:.
- #type ⇒ Object
-
#valid? ⇒ Boolean
check boxes cannot be invalid, as both checked and unchecked are valid states :nocov:.
- #values_disambiguate_template_names? ⇒ Boolean
Methods inherited from Input
#add_input_aria, #add_input_classes, #add_input_data, #add_label_classes, #autofocus!, #caption?, #caption_id, #caption_template?, #disabled?, #focusable?, #full_width?, #hidden?, #id, #input?, #input_width, #invalid?, #merge_input_arguments!, #remove_input_data, #render_caption_template, #required?, #size, #validation_arguments, #validation_error_icon_target, #validation_id, #validation_message_arguments, #validation_messages, #validation_success_icon_target
Methods included from ClassNameHelper
Constructor Details
#initialize(name:, label:, value: nil, unchecked_value: nil, scheme: DEFAULT_SCHEME, **system_arguments) {|_self| ... } ⇒ CheckBoxInput
Returns a new instance of CheckBoxInput.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/lib/primer/forms/dsl/check_box_input.rb', line 13 def initialize(name:, label:, value: nil, unchecked_value: nil, scheme: DEFAULT_SCHEME, **system_arguments) raise ArgumentError, "Check box scheme must be one of #{SCHEMES.join(', ')}" unless SCHEMES.include?(scheme) raise ArgumentError, "Check box needs an explicit value if scheme is array" if scheme == :array && value.nil? @name = name @label = label @value = value @unchecked_value = unchecked_value @scheme = scheme super(**system_arguments) yield(self) if block_given? end |
Instance Attribute Details
#label ⇒ Object (readonly)
Returns the value of attribute label.
11 12 13 |
# File 'app/lib/primer/forms/dsl/check_box_input.rb', line 11 def label @label end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'app/lib/primer/forms/dsl/check_box_input.rb', line 11 def name @name end |
#nested_form_arguments ⇒ Object (readonly)
Returns the value of attribute nested_form_arguments.
11 12 13 |
# File 'app/lib/primer/forms/dsl/check_box_input.rb', line 11 def nested_form_arguments @nested_form_arguments end |
#nested_form_block ⇒ Object (readonly)
Returns the value of attribute nested_form_block.
11 12 13 |
# File 'app/lib/primer/forms/dsl/check_box_input.rb', line 11 def nested_form_block @nested_form_block end |
#scheme ⇒ Object (readonly)
Returns the value of attribute scheme.
11 12 13 |
# File 'app/lib/primer/forms/dsl/check_box_input.rb', line 11 def scheme @scheme end |
#unchecked_value ⇒ Object (readonly)
Returns the value of attribute unchecked_value.
11 12 13 |
# File 'app/lib/primer/forms/dsl/check_box_input.rb', line 11 def unchecked_value @unchecked_value end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
11 12 13 |
# File 'app/lib/primer/forms/dsl/check_box_input.rb', line 11 def value @value end |
Instance Method Details
#nested_form(**system_arguments, &block) ⇒ Object
40 41 42 43 |
# File 'app/lib/primer/forms/dsl/check_box_input.rb', line 40 def nested_form(**system_arguments, &block) @nested_form_arguments = system_arguments @nested_form_block = block end |
#supports_validation? ⇒ Boolean
49 50 51 |
# File 'app/lib/primer/forms/dsl/check_box_input.rb', line 49 def supports_validation? false end |
#to_component ⇒ Object
:nocov:
36 37 38 |
# File 'app/lib/primer/forms/dsl/check_box_input.rb', line 36 def to_component CheckBox.new(input: self) end |
#type ⇒ Object
45 46 47 |
# File 'app/lib/primer/forms/dsl/check_box_input.rb', line 45 def type :check_box end |
#valid? ⇒ Boolean
check boxes cannot be invalid, as both checked and unchecked are valid states :nocov:
31 32 33 |
# File 'app/lib/primer/forms/dsl/check_box_input.rb', line 31 def valid? true end |
#values_disambiguate_template_names? ⇒ Boolean
53 54 55 56 57 |
# File 'app/lib/primer/forms/dsl/check_box_input.rb', line 53 def values_disambiguate_template_names? # Check boxes submitted as an array all have the same name, so we return true here # to ensure different caption templates can be attached to individual check box inputs. @scheme == :array end |