Class: Formtastic::Inputs::NumberInput
- Inherits:
-
Object
- Object
- Formtastic::Inputs::NumberInput
- Includes:
- Base, Base::Stringish
- Defined in:
- lib/formtastic/inputs/number_input.rb
Overview
Outputs a simple <label> with a HTML5 <input type="number"> wrapped in the standard
<li> wrapper. This is the default input choice for all database columns of the type :float
and :decimal, as well as :integer columns that aren't used for belongs_to associations,
but can be applied to any text-like input with :as => :number.
Sensible default values for the min, max and step attributes are found by reflecting on
the model's validations (when provided). An IndeterminableMinimumAttributeError exception
will be raised when the following conditions are all true:
- you haven't specified a
:minor:maxfor the input - the model's database column type is a
:floator:decimal - the validation uses
:less_thanor:greater_than
The solution is to either:
- manually specify the
:minor:maxfor the input - change the database column type to an
:integer(if appropriate) - change the validations to use
:less_than_or_equal_toor:greater_than_or_equal_to
Direct Known Subclasses
Instance Attribute Summary
Attributes included from Base
#builder, #method, #object, #object_name, #options, #template
Instance Method Summary collapse
- #in_option ⇒ Object
- #input_html_options ⇒ Object
- #max_option ⇒ Object
- #min_option ⇒ Object
- #step_option ⇒ Object
- #to_html ⇒ Object
Methods included from Base::Stringish
#placeholder_text, #wrapper_html_options
Methods included from Base
#initialize, #warn_and_correct_option!
Methods included from Base::Wrapping
#input_wrapping, #wrapper_dom_id, #wrapper_html_options
Methods included from Base::Labelling
#label_from_options, #label_html, #label_html_options, #label_text, #localized_label, #render_label?, #requirement_text, #requirement_text_or_proc
Methods included from Base::Associations
#association, #association_primary_key, #belongs_to?, #has_many?, #reflection
Methods included from Base::Fileish
Methods included from Base::Validations
#autofocus?, #column_limit, #limit, #not_required_through_negated_validation!, #not_required_through_negated_validation?, #optional?, #required?, #required_attribute?, #responds_to_global_required?, #validation_integer_only?, #validation_limit, #validation_max, #validation_min, #validation_step, #validations, #validations?, #validator_relevant?
Methods included from Base::Naming
#as, #attributized_method_name, #humanized_method_name, #input_name, #sanitized_method_name, #sanitized_object_name
Methods included from Base::Hints
#hint?, #hint_html, #hint_text, #hint_text_from_options
Methods included from Base::Errors
#error_first_html, #error_html, #error_keys, #error_list_html, #error_none_html, #error_sentence_html, #errors, #errors?
Methods included from Base::Database
Methods included from Base::Options
#formtastic_options, #input_options
Methods included from Base::Html
Instance Method Details
#in_option ⇒ Object
112 113 114 |
# File 'lib/formtastic/inputs/number_input.rb', line 112 def in_option [:in] end |
#input_html_options ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/formtastic/inputs/number_input.rb', line 81 def defaults = super if in_option defaults[:min] = in_option.to_a.min defaults[:max] = in_option.to_a.max else defaults[:min] ||= min_option defaults[:max] ||= max_option end defaults[:step] ||= step_option defaults end |
#max_option ⇒ Object
107 108 109 110 |
# File 'lib/formtastic/inputs/number_input.rb', line 107 def max_option return [:max] if .key?(:max) validation_max end |
#min_option ⇒ Object
102 103 104 105 |
# File 'lib/formtastic/inputs/number_input.rb', line 102 def min_option return [:min] if .key?(:min) validation_min end |
#step_option ⇒ Object
95 96 97 98 99 100 |
# File 'lib/formtastic/inputs/number_input.rb', line 95 def step_option return [:step] if .key?(:step) return validation_step if validation_step return 1 if validation_integer_only? "any" end |
#to_html ⇒ Object
74 75 76 77 78 79 |
# File 'lib/formtastic/inputs/number_input.rb', line 74 def to_html input_wrapping do label_html << builder.number_field(method, ) end end |