ValidForm::Container (Module)

In: ValidForm.rb
ValidForm_html.rb

A wrapper module for methods shared by ValidForm, ::Fieldset, and ::OptionSet.

Attributes

fields  [R]  All fields in this container as an Array; some ‘fields’ may be sub-containers. See also everyField
name  [R]  Every class that includes ::Container should implement a name method.

Public Instance methods

Returns the contained field with id==idOrName; if none exists, looks for and returns an array of fields where name==idOrName; if neither exist, returns nil.

Add one or more fields or field containers (fieldsets) to the container. Returns a reference to the receiver, for simple chaining and nesting:

  search = ValidForm.new('search.rhtml','GET')
  search.add_fields(
     ValidForm::Text.new('q','q',nil,'Find:'),
     ValidForm::OptionSet.new('sections',nil,nil,'Look In:').add_fields(
             ValidForm::Option.new('s1','slashdot.org','/.'),
             ValidForm::Option.new('s2','google.com','Google'),
             ValidForm::Option.new('s3','apple.com','Apple')
     )
  )

Note that the id for each item added must be unique, or an error will be raised.

Sets which classes of items are allowed inside this container. By default, any type of object may be passed to add_fields.

(This method is used by classes including this module; you should never need to invoke it directly.

  class ValidForm
     include FieldContainer
     def initialize
             #...
             allowed_container_classes( ValidForm::Fieldset, ValidForm::Field )
     end
  end

An array of all fields in this container as a flat Array, whether directly in this container or sub-containers. Pass true for includeContainers to have subcontainers themselves included in addition to the fields they contain.

  myForm = ValidForm.new().add_fields(
     foo=ValidForm::Field.new('foo'),
     bar=ValidForm::Fieldset.new('bar').add_fields(
             jim=ValidForm::Field.new('jim'),
             jam=ValidForm::Field.new('jam')
     )
  )

  myForm.fields.each{ |f| print f.id,',' }
    => 'foo,bar,'
  myForm.everyField.each{ |f| print f.id,',' }
    => 'foo,jim,jam,'
  myForm.everyField(true).each{ |f| print f.id,',' }
    => 'foo,bar,jim,jam,'

Return the field in the container with id==id. If no such field exists, nil is returned.

See also fieldsByName and #[].

Returns an Array of all fields in the container with name==name, whether they are in the top-level container (form) or a sub-container (fieldset). If no fields with name exist, nil will be returned.

See also fieldById and #[].

Returns the parent container for the receiving container; nil if none exists.

[Validate]