Class: Brut::FrontEnd::Forms::RadioButtonGroupInput
- Inherits:
-
Object
- Object
- Brut::FrontEnd::Forms::RadioButtonGroupInput
- Extended by:
- Forwardable
- Defined in:
- lib/brut/front_end/forms/radio_button_group_input.rb
Instance Attribute Summary collapse
-
#typed_value ⇒ Date|Time|BigDecimal|String|true|false|nil
readonly
The value of the input, as coerced to the type used to evaluate constraints.
-
#validity_state ⇒ Brut::FrontEnd::Forms::ValidityState
readonly
Validity state that captures the current constraint violations, if any.
-
#value ⇒ String
The input's value.
Instance Method Summary collapse
-
#initialize(input_definition:, value:, index:) ⇒ RadioButtonGroupInput
constructor
Create the input with the given definition and value.
-
#server_side_constraint_violation(key, context = true) ⇒ Object
Set a server-side constraint violation on this input.
-
#valid? ⇒ true|false
True if the underlying #validity_state has no constraint violations.
Constructor Details
#initialize(input_definition:, value:, index:) ⇒ RadioButtonGroupInput
Create the input with the given definition and value
15 16 17 18 19 20 21 22 23 |
# File 'lib/brut/front_end/forms/radio_button_group_input.rb', line 15 def initialize(input_definition:, value:, index:) @input_definition = input_definition @validity_state = Brut::FrontEnd::Forms::ValidityState.new @index = index if input_definition.array? value ||= [] end self.value=(value) end |
Instance Attribute Details
#typed_value ⇒ Date|Time|BigDecimal|String|true|false|nil (readonly)
The value of the input,
as coerced to the type used to evaluate constraints.
Returns nil
if the value could not be coerced (which likely means
there is or will be a constraint violation), or
if it is a blank String.
Of note, type=color
will return a String here, but that String
should be parseable into a hex code, i.e. #XXXXXX, where each "X"
is 0-9 or a-f. Further, type=time
will also return a string
in the format HH:MM or HH:MM:SS, where the time is in 24 hour
time. Lastly, type=datetime-local
will return a Time
, even
though the control allows the visitor to choose an invalid time.
If there is no valueMissing
constraint violation, but this
attribute returns nil
, #value will return the string sent by
the browser, even if it's not a real timestamp.
9 10 11 |
# File 'lib/brut/front_end/forms/radio_button_group_input.rb', line 9 def typed_value @typed_value end |
#validity_state ⇒ Brut::FrontEnd::Forms::ValidityState (readonly)
Returns Validity state that captures the current constraint violations, if any.
12 13 14 |
# File 'lib/brut/front_end/forms/radio_button_group_input.rb', line 12 def validity_state @validity_state end |
#value ⇒ String
Returns the input's value. DO NOTE this returns a string. This is
because HTML stores these values as Strings. When using a checkbox, in
particular, the value will not be a boolean. You cannot do if
input.value
and expect that work. See #typed_value instead.
6 7 8 |
# File 'lib/brut/front_end/forms/radio_button_group_input.rb', line 6 def value @value end |
Instance Method Details
#server_side_constraint_violation(key, context = true) ⇒ Object
Set a server-side constraint violation on this input. This is essentially arbitrary, but note
that key
should not be a key used for client-side validations.
48 49 50 |
# File 'lib/brut/front_end/forms/radio_button_group_input.rb', line 48 def server_side_constraint_violation(key,context=true) @validity_state.server_side_constraint_violation(key: key, context: context) end |
#valid? ⇒ true|false
Returns true if the underlying #validity_state has no constraint violations.
53 |
# File 'lib/brut/front_end/forms/radio_button_group_input.rb', line 53 def valid? = @validity_state.valid? |