/** * @return string */ public function getInput() { $res = $this->renderTemplate(); if ($res !== null) { return $res; } $list = $this->getList(); if (!empty($this->prompt)) { $oldList = $list; $list = array('' => $this->prompt); foreach ($oldList as $key => $val) { $list[$key] = $val; } } $value = $this->getValue(); $options = $this->getAttributes(); if ($this->isMultiple()) { $options['multiple'] = 'multiple'; } else { unset($options['multiple']); } $options['name'] = $this->getNameChainString(); $isMultiple = $this->isMultiple(); $content = ''; $listItemsOptions = $this->getListItemsOptions(); foreach ($list as $optionValue => $optionContent) { $optionOptions = isset($listItemsOptions[$optionValue]) && is_array($listItemsOptions[$optionValue]) ? $listItemsOptions[$optionValue] : []; $optionOptions['value'] = $optionValue; if ($optionValue !== '' && $value !== null && (!$isMultiple && $optionValue == $value || $isMultiple && is_array($value) && in_array($optionValue, $value))) { $optionOptions['selected'] = 'selected'; } $content .= Html::tag('option', $optionOptions, Html::clearText($optionContent)); } return Html::tag('select', $options, $content); }
/** * @return string */ public function getInput() { $res = $this->renderTemplate(); if ($res !== null) { return $res; } $list = $this->getList(); $value = $this->getValue(); $options = $this->getAttributes(); $options['name'] = $this->getNameChainString(); $isMultiple = $this->multiple; $content = ''; $listItemsOptions = $this->getListItemsOptions(); foreach ($list as $optionValue => $optionContent) { $optionOptions = isset($listItemsOptions[$optionValue]) && is_array($listItemsOptions[$optionValue]) ? array_merge($options, $listItemsOptions[$optionValue]) : $options; $optionOptions['value'] = $optionValue; $optionOptions['type'] = $isMultiple ? 'checkbox' : 'radio'; $optionOptions['id'] = Html::toId($options['name'] . '_' . $optionValue); if ($value !== null && (!$isMultiple && $optionValue == $value || $isMultiple && is_array($value) && in_array($optionValue, $value))) { $optionOptions['checked'] = 'checked'; } $option = Html::tag('input', $optionOptions, false); $labelOptions = $this->getLabelOptions(); $labelOptions['for'] = $optionOptions['id']; $content .= Html::tag('label', $labelOptions, $option . Html::clearText($optionContent)); } return $content; }
/** * @return string */ public function getInput() { $res = $this->renderTemplate(); if ($res !== null) { return $res; } $attrubutes = $this->getAttributes(); $attrubutes['name'] = $this->getNameChainString(); return Html::tag('textarea', $attrubutes, Html::clearText($this->getValue())); }
/** * @return string */ public function getInput() { $res = $this->renderTemplate(); if ($res !== null) { return $res; } $options = $this->getAttributes(); $options['name'] = $this->getNameChainString(); $value = $this->getValue(); if ($value !== null) { $options['value'] = $value; } return Html::tag('button', $options, $this->allowHtmlContent ? $this->getLabel() : Html::clearText($this->getLabel())); }
</div> <?php } else { ?> <div class="form-group<?php if (!empty($errors)) { echo ' has-error'; } ?> "> <label for="<?php echo Html::clearAttribute($el->getAttribute('id')); ?> " class="col-sm-3 control-label"> <?php echo Html::clearText($el->getLabel()); ?> </label> <div class="col-sm-9"> <?php echo $el->addToAttribute('class', ' form-control')->getInput(); ?> <?php if (!empty($errors)) { ?> <span class="help-block"><?php echo implode(', ', $errors); ?> </span> <?php }
/** * @dataProvider clearTextProvider */ public function testClearText($string, $expected) { $res = \serviform\helpers\Html::clearText($string); $this->assertEquals($expected, $res); }