Class: Bureaucrat::Fields::CharField
- Defined in:
- lib/bureaucrat/fields.rb
Direct Known Subclasses
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, #validators, #widget
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ CharField
constructor
A new instance of CharField.
- #to_object(value) ⇒ Object
- #widget_attrs(widget) ⇒ Object
Methods inherited from Field
#bound_data, #clean, #default_error_messages, #default_hidden_widget, #default_validators, #default_widget, #initialize_copy, #populate_object, #prepare_value, #run_validators, #validate
Constructor Details
#initialize(options = {}) ⇒ CharField
Returns a new instance of CharField.
186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/bureaucrat/fields.rb', line 186 def initialize( = {}) @max_length = .delete(:max_length) @min_length = .delete(:min_length) super() if @min_length validators << Validators::MinLengthValidator.new(@min_length) end if @max_length validators << Validators::MaxLengthValidator.new(@max_length) end end |
Instance Attribute Details
#max_length ⇒ Object
Returns the value of attribute max_length.
184 185 186 |
# File 'lib/bureaucrat/fields.rb', line 184 def max_length @max_length end |
#min_length ⇒ Object
Returns the value of attribute min_length.
184 185 186 |
# File 'lib/bureaucrat/fields.rb', line 184 def min_length @min_length end |
Instance Method Details
#to_object(value) ⇒ Object
200 201 202 203 204 205 206 |
# File 'lib/bureaucrat/fields.rb', line 200 def to_object(value) if Validators.empty_value?(value) '' else value end end |
#widget_attrs(widget) ⇒ Object
208 209 210 211 212 213 214 215 |
# File 'lib/bureaucrat/fields.rb', line 208 def () super().tap do |attrs| if @max_length && (.kind_of?(Widgets::TextInput) || .kind_of?(Widgets::PasswordInput)) attrs.merge(maxlength: @max_length.to_s) end end end |