Exemple #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;
 }
Exemple #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);
 }
Exemple #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());
 }
Exemple #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()));
 }
Exemple #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);
 }
Exemple #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);
 }
Exemple #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()));
 }
Exemple #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;
 }
Exemple #9
0
                <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 
        }
        ?>
                </div>
            </div>
        <?php 
    }
    ?>
    <?php 
}
echo Html::closeTag($tag);
Exemple #10
0
 /**
  * @dataProvider clearTextProvider
  */
 public function testClearText($string, $expected)
 {
     $res = \serviform\helpers\Html::clearText($string);
     $this->assertEquals($expected, $res);
 }
Exemple #11
0
 /**
  * @return string
  */
 public function getBeginTag()
 {
     $attrubutes = $this->getAttributes();
     return Html::tag('form', $attrubutes, true);
 }