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



45
46
47
# File 'app/fields/controllers/main_controller.rb', line 45

def blur
  model_inst.mark_field!(@field_name)
end

#errorsObject

Find the errors for this field



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

def errors
  model_inst.marked_errors[@field_name]
end

#field_nameObject



40
41
42
# File 'app/fields/controllers/main_controller.rb', line 40

def field_name
  @field_name
end

#labelObject



29
30
31
32
33
# File 'app/fields/controllers/main_controller.rb', line 29

def label
  unless ['false','False'].include?(attrs.label)
    attrs.label || @field_name.titleize
  end
end

#markedObject



49
50
51
# File 'app/fields/controllers/main_controller.rb', line 49

def marked
  model_inst.marked_fields[@field_name]
end

#model_instObject

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



25
26
27
# File 'app/fields/controllers/main_controller.rb', line 25

def model_inst
  attrs.value_parent
end

#setup_fieldObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/fields/controllers/main_controller.rb', line 6

def setup_field
  # Default to text fields
  if attrs.respond_to?(:type)
    @type = attrs.type
  else
    @type = 'text'
  end

  unless attrs.value_last_method
    field_type = self.class.to_s.underscore.gsub(/[_]Controller$/, '')
    raise "a <:fields:#{field_type} tag was used without passing a value attribute"
  end

  # Get the name of the field by looking at the method scope
  @field_name = attrs.value_last_method.gsub(/^[_]/, '')
end