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.



477
478
479
# File 'lib/forme.rb', line 477

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

Instance Attribute Details

#formObject (readonly)

The Form object related to the receiver.



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

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.



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

def opts
  @opts
end

#typeObject (readonly)

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



449
450
451
# File 'lib/forme.rb', line 449

def type
  @type
end

Instance Method Details

#formatObject

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



500
501
502
# File 'lib/forme.rb', line 500

def format
  form.format(self)
end

#merge_opts(hash) ⇒ Object

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



483
484
485
# File 'lib/forme.rb', line 483

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.



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

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

#to_sObject

Return a string containing the serialized content of the receiver.



494
495
496
# File 'lib/forme.rb', line 494

def to_s
  form.serialize(self)
end