Exemplo n.º 1
0
 /**
  * @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;
 }
Exemplo n.º 2
0
 /**
  * @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);
 }
Exemplo n.º 3
0
 /**
  * @return string
  */
 public function getInput()
 {
     $res = $this->renderTemplate();
     if ($res !== null) {
         return $res;
     }
     $attrubutes = $this->getAttributes();
     return Html::tag('div', $attrubutes, $this->getValue());
 }
Exemplo n.º 4
0
 /**
  * @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()));
 }
Exemplo n.º 5
0
 /**
  * @return string
  */
 public function getInput()
 {
     $res = $this->renderTemplate();
     if ($res !== null) {
         return $res;
     }
     $attrubutes = $this->getAttributes();
     $attrubutes['value'] = $this->getValue();
     $attrubutes['name'] = $this->getNameChainString();
     if (empty($attrubutes['type'])) {
         $attrubutes['type'] = 'text';
     }
     return Html::tag('input', $attrubutes, false);
 }
Exemplo n.º 6
0
 /**
  * @return string
  */
 public function getInput()
 {
     $res = $this->renderTemplate();
     if ($res !== null) {
         return $res;
     }
     $return = '';
     $elements = $this->getElements();
     $itemAttributes = $this->getItemAttributes();
     foreach ($elements as $el) {
         $return .= Html::tag('div', $itemAttributes, $el->getInput());
     }
     return Html::tag('div', $this->getAttributes(), $return);
 }
Exemplo n.º 7
0
 /**
  * @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()));
 }
Exemplo n.º 8
0
 /**
  * @return string
  */
 public function getInput()
 {
     $res = $this->renderTemplate();
     if ($res !== null) {
         return $res;
     }
     $value = $this->getValue();
     $options = $this->getAttributes();
     $options['name'] = $this->getNameChainString();
     $options['value'] = $this->trueValue;
     $options['type'] = 'checkbox';
     if ($value == $this->trueValue) {
         $options['checked'] = 'checked';
     }
     $option = Html::tag('input', $options, false);
     $disableOptions = array('type' => 'hidden', 'name' => $options['name'], 'value' => $this->falseValue);
     $disableOption = Html::tag('input', $disableOptions, false);
     return $disableOption . $option;
 }
Exemplo n.º 9
0
<?php

use serviform\helpers\Html;
if ($this->getParent()) {
    $tag = 'fieldset';
} else {
    $tag = 'form';
    $this->addToAttribute('class', ' form-horizontal');
}
echo Html::tag($tag, $this->getAttributes(), false);
if ($tag === 'fieldset' && $this->getLabel()) {
    echo Html::tag('legend', null, $this->getLabel());
}
$els = $this->getElements();
//show hidden element first
foreach ($els as $key => $el) {
    if ($el->getAttribute('type') !== 'hidden') {
        continue;
    }
    echo $el->getInput();
    unset($els[$key]);
}
?>
    <?php 
foreach ($els as $el) {
    $errors = $el->getErrors();
    ?>
        <?php 
    if ($el instanceof \serviform\IChildable) {
        ?>
            <?php 
Exemplo n.º 10
0
 /**
  * @dataProvider tagProvider
  */
 public function testTag($tag, $options, $content, $expected)
 {
     $res = \serviform\helpers\Html::tag($tag, $options, $content);
     $this->assertEquals($expected, $res);
 }
Exemplo n.º 11
0
 /**
  * @return string
  */
 public function getBeginTag()
 {
     $attrubutes = $this->getAttributes();
     return Html::tag('form', $attrubutes, true);
 }