Contents

CheckSet

The CheckSet presents items as checkboxes.

Normal CheckSet

CheckSetTable

Item 1Item 2Item 3
<?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