/** * Генерация тега SELECT со списком опций * @return Select */ public function asSelect($placeholder = null, $attr = null, $value = null) { if (!($options = $this->getOptions())) { return false; } $s = new Select($this->getColumn(), $options, !is_null($value) ? $value : $this->getCleanValue(), $attr, $placeholder); if ($this->getOptionsIgnoreKeys()) { $s->setIgnoreOptionsKeys(true); } return $s; }
/** @return TagWithOptions */ public function render($attr = null) { $opts = $this->getOptions(); if ($ph = $this->getPlaceholder()) { $opts = array('' => $ph) + (!empty($opts) ? $opts : array()); } $t = new Select($this->getInputName(), $opts, $this->getValue(), $this->prepareAttr($attr)); if ($this->getIgnoreOptionsKeys()) { $t->setIgnoreOptionsKeys(true); } return $t; }
function testSelect() { $t = new Tag\Select('type', array(1 => 'one', 2 => 'two'), 2, 'one'); $exp = '<select class="one" name="type">' . '<option value="1">one</option>' . "\n" . '<option selected="selected" value="2">two</option>' . "\n" . '</select>'; $this->assertEquals($exp, $t->toHTML(), 'Стандартный рендер'); $t->setIgnoreOptionsKeys(true); $t->setSelected('one'); $t->setPlaceholder('Выберите'); $exp = '<select class="one" name="type"><option value="">Выберите</option>' . "\n" . '<option selected="selected" value="one">one</option>' . "\n" . '<option value="two">two</option>' . "\n" . '</select>'; $this->assertEquals($exp, $t->toHTML(), 'Стандартный рендер'); }