Class: Fields::TextController

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

Direct Known Subclasses

TextareaController

Instance Method Summary collapse

Instance Method Details

#blurObject

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

#errorsObject

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

Returns:

  • (Boolean)


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

def icon?
  return attrs.icon.present?
end

#indexObject



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_readyObject



15
16
17
# File 'app/fields/controllers/text_controller.rb', line 15

def index_ready
  set_label
end

#labelObject



29
30
31
# File 'app/fields/controllers/text_controller.rb', line 29

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

#label_idObject



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

def label_id
  return label.gsub(/\s+/, "").downcase
end

#markedObject



53
54
55
# File 'app/fields/controllers/text_controller.rb', line 53

def marked
  model.marked_fields[@field_name]
end

#modelObject

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_labelObject



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