FieldCollection - Page-Carbajal/WPExpress GitHub Wiki

##Class WPExpress/UI/FieldCollection

The FieldCollection class helps you create a collection of HTML Field Objects Definitions.

###What do I mean by Definition?

When you add a field to the collection, it manages the data but doesn't render HTML.

The class has a container property accessible through the class methods and some interfaces implemented for this purpose.

Think of this class as a helper for defining the HTML fields you want to use, their properties and values.

##Methods

###addTextInput

$fields = new FieldCollection();

$fields->addTextInput('mytext');
$fields->addSelect('myselect');

All fields can be defined with a single property name, you can use methods like setID and setAttribute to further extend the definition.

**Adding a custom ID on declaration

$fields = new FieldCollection();

$fields->addTextInput('mytext')->setID('my-text-1');

**Adding a custom ID on two steps

$fields = new FieldCollection();

$fields->addTextInput('mytext');
$fields->addSelect('myselect'); //If not specified ID will be made equals to name 
// Some more code and fields
$fields->field('mytext')->setID('my-text-1');

##Warning

Methods like setID, setAttribute, setAttributes are related to the las active field. To set the ID of a control after declaration you need to use field method to indicate which field you are affecting.