Class: Forme::Labeler::Explicit

Inherits:
Object
  • Object
show all
Defined in:
lib/forme.rb

Overview

Explicit labeler that creates a separate label tag that references the given tag’s id using a for attribute. Requires that all tags with labels have id fields.

Registered as :explicit.

Instance Method Summary collapse

Instance Method Details

#call(tag, input) ⇒ Object

Return an array with a label tag as the first entry and tag as a second entry. If the input has a :label_for option, use that, otherwise use the input’s :id option. If neither the :id or :label_for option is used, the label created will not be associated with an input.



953
954
955
# File 'lib/forme.rb', line 953

def call(tag, input)
  [input.tag(:label, {:for=>input.opts.fetch(:label_for, input.opts[:id])}.merge(input.opts[:label_attr]||{}), [input.opts[:label]]), tag]
end