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
CheckSet
The CheckSet
presents items as checkboxes.
<?php
namespace Rhubarb\Leaf\Controls\Common\Examples\SelectionControls;
use Rhubarb\Leaf\Controls\Common\SelectionControls\CheckSet\CheckSet;
use Rhubarb\Leaf\Controls\Common\SelectionControls\CheckSetTable\CheckSetTable;
use Rhubarb\Leaf\Views\View;
class CheckSetExampleView extends View
{
protected function createSubLeaves()
{
$this->registerSubLeaf(
$control = new CheckSet("control"),
$table = new CheckSetTable("table")
);
$control->setSelectionItems(
[
"Item 1",
"Item 2",
[ 3, "Item 3"],
ExampleContact::all()->addSort("FirstName")
]
);
$table->setSelectionItems(
[
"Item 1",
"Item 2",
[ 3, "Item 3"]
]
);
}
protected function printViewContent()
{
print "<h3>Normal CheckSet</h3>";
print $this->leaves["control"];
print "<h3>CheckSetTable</h3>";
print $this->leaves["table"];
}
}
Two variants exist CheckSet
which outputs each checkset with a label one after the other and
CheckSetTable
which formats the set into a table.
Customising the view
The CheckSetView
is quite often overridden to customise how the checkboxes are laid out.
As CheckSet
is a SetSelectionControl
it's view has three methods you can override:
- getItemOptionHtml($value, $label, $item)
- Returns the HTML for a given item. The result of this function is printed one after the other. In turn this should call the remaining two functions.
- getInputHtml($name, $value, $item)
- Returns the HTML for the checkbox input itself
- getLabelHtml($label, $inputId)
- Returns the HTML for the label.
$inputId
can be used to reference the input's document ID for example in a <label for="""> tag