Class: Fields::TextController
- Inherits:
-
Volt::ModelController
- Object
- Volt::ModelController
- Fields::TextController
- Defined in:
- app/fields/controllers/text_controller.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#blur ⇒ Object
When a field goes out of focus, then we want to start checking a field.
-
#errors ⇒ Object
Find the errors for this field.
- #icon? ⇒ Boolean
- #index ⇒ Object
- #index_ready ⇒ Object
- #label ⇒ Object
- #label_id ⇒ Object
- #marked ⇒ Object
-
#model ⇒ Object
Find the parent reactive value that produced the value (usually just model._field).
- #set_label ⇒ Object
Instance Method Details
#blur ⇒ Object
When a field goes out of focus, then we want to start checking a field
49 50 51 |
# File 'app/fields/controllers/text_controller.rb', line 49 def blur attrs.value_parent.mark_field!(@field_name) end |
#errors ⇒ Object
Find the errors for this field
44 45 46 |
# File 'app/fields/controllers/text_controller.rb', line 44 def errors model.marked_errors[@field_name] end |
#icon? ⇒ Boolean
25 26 27 |
# File 'app/fields/controllers/text_controller.rb', line 25 def icon? return attrs.icon.present? end |
#index ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 |
# File 'app/fields/controllers/text_controller.rb', line 3 def index # Default to text fields if attrs.respond_to?(:type) @type = attrs.type else @type = 'text' end # Get the name of the field by looking at the method scope @field_name = attrs.value_last_method.gsub(/^[_]/, '') end |
#index_ready ⇒ Object
15 16 17 |
# File 'app/fields/controllers/text_controller.rb', line 15 def index_ready set_label end |
#label ⇒ Object
29 30 31 |
# File 'app/fields/controllers/text_controller.rb', line 29 def label return attrs.label || @field_name.titleize end |
#label_id ⇒ Object
33 34 35 |
# File 'app/fields/controllers/text_controller.rb', line 33 def label_id return label.gsub(/\s+/, "").downcase end |
#marked ⇒ Object
53 54 55 |
# File 'app/fields/controllers/text_controller.rb', line 53 def marked model.marked_fields[@field_name] end |
#model ⇒ Object
Find the parent reactive value that produced the value (usually just model._field)
21 22 23 |
# File 'app/fields/controllers/text_controller.rb', line 21 def model attrs.value_parent end |
#set_label ⇒ Object
37 38 39 40 41 |
# File 'app/fields/controllers/text_controller.rb', line 37 def set_label input_item = Element[".input-field[item=#{label_id}]"] input_item_id = input_item.find('input').attr('id') input_item.find('label').attr('for', input_item_id) end |