Class: Fields::MainController

Inherits:
Volt::ModelController
  • Object
show all
Defined in:
app/fields/controllers/main_controller.rb

Instance Method Summary collapse

Instance Method Details

#blurObject

When a field goes out of focus, then we want to start checking a field



33
34
35
# File 'app/fields/controllers/main_controller.rb', line 33

def blur
  model.mark_field!(@field_name)
end

#errorsObject

Find the errors for this field



28
29
30
# File 'app/fields/controllers/main_controller.rb', line 28

def errors
  model.marked_errors[@field_name]
end

#labelObject



23
24
25
# File 'app/fields/controllers/main_controller.rb', line 23

def label
  attrs.label || @field_name.titleize
end

#markedObject



37
38
39
# File 'app/fields/controllers/main_controller.rb', line 37

def marked
  model.marked_fields[@field_name]
end

#modelObject

Find the parent reactive value that produced the value (usually just model._field)



19
20
21
# File 'app/fields/controllers/main_controller.rb', line 19

def model
  attrs.value_parent
end

#setup_fieldObject



5
6
7
8
9
10
11
12
13
14
15
# File 'app/fields/controllers/main_controller.rb', line 5

def setup_field
  # 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