Contents
- Basic Concepts
- Introduction
- Processing user interactions
- Nesting leaves
- Data Binding
- Tutorial
- Building a blog
- View Bridges
- Introduction
- The model
- Re-rendering
- Events
- Handling Children
- Controls
- Extending View Bridges
- Control Components
- What is a control?
- Text Controls
- TextBox
- TextArea
- PasswordTextBox
- Selection Controls
- The selection control pattern
- Standard Variants
- DropDown
- CheckSet
- RadioButtons
- SearchControl
- ModelSearchControl
- Attaching additional data
- Dynamically driving the available items
- File Uploads
- SimpleFileUpload
- Html5FileUpload
- Other
- Buttons
- Building your own control
- Application Components
- What is an application component?
- Pager
- Table
- SearchPanel
- Tabs
- Advanced Topics
- View Indexes
TextBox
The humble text box is perhaps the most common control of all appearing at least once in nearly every single form.
The TextBox
control class has one property in addition to the standard control:
- setMaxLength($length)
- Sets the maximum number of characters the user can enter.
<?php
namespace Rhubarb\Leaf\Controls\Common\Examples\Text\TextBox;
use Rhubarb\Leaf\Leaves\Leaf;
class TextBox extends Leaf
{
/**
* @var TextBoxModel
*/
protected $model;
protected function getViewClass()
{
return TextBoxView::class;
}
protected function createModel()
{
return new TextBoxModel();
}
}
<?php
namespace Rhubarb\Leaf\Controls\Common\Examples\Text\TextBox;
use Rhubarb\Leaf\Leaves\LeafModel;
class TextBoxModel extends LeafModel
{
public $forename;
public $surname;
public $houseNumber;
}
<?php
namespace Rhubarb\Leaf\Controls\Common\Examples\Text\TextBox;
use Rhubarb\Leaf\Controls\Common\Text\TextBox;
use Rhubarb\Leaf\Views\View;
class TextBoxView extends View
{
/**
* @var TextBoxModel
*/
protected $model;
protected function createSubLeaves()
{
$this->registerSubLeaf(
$forename = new TextBox("forename"),
$surname = new TextBox("surname"),
$houseNumber = new TextBox("houseNumber")
);
$forename->setPlaceholderText("Forename");
$surname->setPlaceholderText("Surname");
$houseNumber->setMaxLength(5);
$houseNumber->setPlaceholderText("House No. (limited to 5 characters)");
}
protected function printViewContent()
{
print $this->leaves["forename"]." ".$this->leaves["surname"]." ".$this->leaves["houseNumber"];
}
}