Class: Formulary::HtmlForm::Fields::NumberInput
- Defined in:
- lib/formulary/html_form/fields/number_input.rb
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
- #error ⇒ Object
-
#initialize(html_form, element) ⇒ NumberInput
constructor
A new instance of NumberInput.
- #valid? ⇒ Boolean
Methods inherited from Input
compatible_with?, supports_required?
Methods inherited from Field
#get_value_from_data_field, #is_hidden?, #label, #name, #set_value, supports_required?
Constructor Details
#initialize(html_form, element) ⇒ NumberInput
Returns a new instance of NumberInput.
7 8 9 10 11 12 |
# File 'lib/formulary/html_form/fields/number_input.rb', line 7 def initialize(html_form, element) @html_form, @element = html_form, element @min = @element.attributes['min'].try('value') @max = @element.attributes['max'].try('value') @step = @element.attributes['step'].try('value') end |
Class Method Details
.compatible_type ⇒ Object
3 4 5 |
# File 'lib/formulary/html_form/fields/number_input.rb', line 3 def self.compatible_type "number" end |
Instance Method Details
#error ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/formulary/html_form/fields/number_input.rb', line 18 def error return super if super.present? return "'#{label}' must be a valid number" unless number_correct? return "'#{label}' must be greater than or equal to #{@min}" unless min_correct? return "'#{label}' must be less than or equal to #{@max}" unless max_correct? return "'#{label}' must be a step of #{@step}, the nearest valid values are #{@lower_step} and #{@higher_step}" unless step_correct? end |
#valid? ⇒ Boolean
14 15 16 |
# File 'lib/formulary/html_form/fields/number_input.rb', line 14 def valid? super && number_correct? && min_correct? && max_correct? && step_correct? end |