Sha256: 9b164a384efdad3f040b70bb4c39c16b77be555a67e5431632be180418ce1a26

Contents?: true

Size: 883 Bytes

Versions: 3

Compression:

Stored size: 883 Bytes

Contents

module Fields
  class TextController < Volt::ModelController
    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

    # Find the parent reactive value that produced the value
    # (usually just model._field)
    def model
      attrs.value_parent
    end

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

    # Find the errors for this field
    def errors
      model.marked_errors[@field_name]
    end

    # When a field goes out of focus, then we want to start checking a field
    def blur
      attrs.value_parent.mark_field!(@field_name)
    end

    def marked
      model.marked_fields[@field_name]
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
volt-fields-0.1.0 app/fields/controllers/text_controller.rb
volt-fields-0.0.13 app/fields/controllers/text_controller.rb
volt-fields-0.0.12 app/fields/controllers/text_controller.rb