TbHtml::listBox PHP Method

listBox() public static method

Generates a list box.
public static listBox ( string $name, mixed $select, array $data, array $htmlOptions = [] ) : string
$name string the input name.
$select mixed the selected value(s).
$data array data for generating the list options (value=>display).
$htmlOptions array additional HTML attributes.
return string the generated list box
    public static function listBox($name, $select, $data, $htmlOptions = array())
    {
        if (isset($htmlOptions['multiple'])) {
            if (substr($name, -2) !== '[]') {
                $name .= '[]';
            }
        }
        TbArray::defaultValue('displaySize', 4, $htmlOptions);
        return self::dropDownList($name, $select, $data, $htmlOptions);
    }

Usage Example

Example #1
0
 public function testListBox()
 {
     $I = $this->codeGuy;
     $html = TbHtml::listBox('listbox', null, array('1', '2', '3', '4', '5'), array('class' => 'list', 'empty' => 'Empty text', 'size' => TbHtml::INPUT_SIZE_LARGE, 'textAlign' => TbHtml::TEXT_ALIGN_CENTER));
     $select = $I->createNode($html, 'select');
     $I->seeNodeCssClass($select, 'input-large text-center list');
     $I->seeNodeAttributes($select, array('name' => 'listbox', 'id' => 'listbox', 'size' => 4));
     $html = TbHtml::listBox('listbox', null, array('1', '2', '3', '4', '5'), array('multiple' => true));
     $select = $I->createNode($html, 'select');
     $I->seeNodeAttribute($select, 'name', 'listbox[]');
 }
TbHtml