Class: Bureaucrat::Fields::CharField
- Defined in:
- lib/bureaucrat/fields.rb
Direct Known Subclasses
Constant Summary
Constants included from Validation::Validators
Validation::Validators::EMAIL_RE
Instance Attribute Summary collapse
-
#max_length ⇒ Object
Returns the value of attribute max_length.
-
#min_length ⇒ Object
Returns the value of attribute min_length.
Attributes inherited from Field
#error_messages, #help_text, #hidden_widget, #initial, #label, #required, #show_hidden_initial, #widget
Instance Method Summary collapse
- #clean(value) ⇒ Object
-
#initialize(options = {}) ⇒ CharField
constructor
A new instance of CharField.
- #widget_attrs(widget) ⇒ Object
Methods inherited from Field
hidden_widget, inherited, #initialize_copy, set_error, #validating, widget
Methods included from Validation::Converters
to_big_decimal, to_bool, to_float, to_integer
Methods included from Validation::Validates
Methods included from Validation::Validators
empty_value?, has_max_decimal_places, has_max_digits, has_max_length, has_max_whole_digits, has_min_length, included_in, is_array, is_email, is_not_greater_than, is_not_lesser_than, is_present, is_true, matches_regex, not_empty
Constructor Details
#initialize(options = {}) ⇒ CharField
Returns a new instance of CharField.
145 146 147 148 149 |
# File 'lib/bureaucrat/fields.rb', line 145 def initialize(={}) @max_length = .delete(:max_length) @min_length = .delete(:min_length) super() end |
Instance Attribute Details
#max_length ⇒ Object
Returns the value of attribute max_length.
143 144 145 |
# File 'lib/bureaucrat/fields.rb', line 143 def max_length @max_length end |
#min_length ⇒ Object
Returns the value of attribute min_length.
143 144 145 |
# File 'lib/bureaucrat/fields.rb', line 143 def min_length @min_length end |
Instance Method Details
#clean(value) ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/bureaucrat/fields.rb', line 157 def clean(value) super(value) return '' if empty_value?(value) validating do has_max_length(value, @max_length) if @max_length has_min_length(value, @min_length) if @min_length end value end |
#widget_attrs(widget) ⇒ Object
151 152 153 154 155 |
# File 'lib/bureaucrat/fields.rb', line 151 def () return if @max_length.nil? return {:maxlength => @max_length.to_s} if .kind_of?(Widgets::TextInput) || .kind_of?(Widgets::PasswordInput) end |