Class: Forme::Input

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

Overview

High level abstract tag form, transformed by formatters into the lower level Tag form (or an array of them).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(form, type, opts = {}) ⇒ Input

Set the form, type, and opts.



473
474
475
# File 'lib/forme.rb', line 473

def initialize(form, type, opts={})
  @form, @type, @opts = form, type, opts
end

Instance Attribute Details

#formObject (readonly)

The Form object related to the receiver.



442
443
444
# File 'lib/forme.rb', line 442

def form
  @form
end

#optsObject (readonly)

The options hash for the receiver. Here are some of the supported options used by the built-in formatter transformers:

:error

Set an error message, invoking the error_handler

:label

Set a label, invoking the labeler

:wrapper

Set a custom wrapper, overriding the form’s default

:labeler

Set a custom labeler, overriding the form’s default

:error_handler

Set a custom error_handler, overriding the form’s default

:attr

The attributes hash to use for the given tag, takes precedence over other options that set attributes.

:data

A hash of data-* attributes for the resulting tag. Keys in this hash will have attributes created with data- prepended to the attribute name.

:name

The name attribute to use

:id

The id attribute to use

:placeholder

The placeholder attribute to use

:value

The value attribute to use for input tags, the content of the textarea for textarea tags, or the selected option(s) for select tags.

:class

A class to use. Unlike other options, this is combined with the classes set in the :attr hash.

:disabled

Set the disabled attribute if true

:required

Set the required attribute if true

For other supported options, see the private methods in Formatter.



470
471
472
# File 'lib/forme.rb', line 470

def opts
  @opts
end

#typeObject (readonly)

The type of input, should be a symbol (e.g. :submit, :text, :select).



445
446
447
# File 'lib/forme.rb', line 445

def type
  @type
end

Instance Method Details

#formatObject

Transform the receiver into a lower level Tag form (or an array of them).



496
497
498
# File 'lib/forme.rb', line 496

def format
  form.format(self)
end

#merge_opts(hash) ⇒ Object

Replace the opts by merging the given hash into opts, without modifying opts.



479
480
481
# File 'lib/forme.rb', line 479

def merge_opts(hash)
  @opts = @opts.merge(hash)
end

#tag(*a, &block) ⇒ Object

Create a new Tag instance with the given arguments and block related to the receiver’s form.



485
486
487
# File 'lib/forme.rb', line 485

def tag(*a, &block)
  form._tag(*a, &block)
end

#to_sObject

Return a string containing the serialized content of the receiver.



490
491
492
# File 'lib/forme.rb', line 490

def to_s
  form.serialize(self)
end