Class: Forme::Labeler::Explicit
- Inherits:
-
Object
- Object
- Forme::Labeler::Explicit
- 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
-
#call(tag, input) ⇒ Object
Return an array with a label tag as the first entry and
tag
as a second entry.
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.
1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 |
# File 'lib/forme.rb', line 1040 def call(tag, input) if [:radio, :checkbox].include?(input.type) t = [tag, input.tag(:label, {:for=>input.opts.fetch(:label_for, input.opts[:id])}.merge(input.opts[:label_attr]||{}), [input.opts[:label]])] p = :before else t = [input.tag(:label, {:for=>input.opts.fetch(:label_for, input.opts[:id])}.merge(input.opts[:label_attr]||{}), [input.opts[:label]]), tag] p = :after end if input.opts[:label_position] == p t.reverse else t end end |