render() public method

This method will generate the label, error tag, input tag and hint tag (if any), and assemble them into HTML according to [[template]].
public render ( string | callable $content = null ) : string
$content string | callable the content within the field container. If `null` (not set), the default methods will be called to generate the label, error tag and input tag, and use them as the content. If a callable, it will be called to generate the content. The signature of the callable should be: ```php function ($field) { return $html; } ```
return string the rendering result.
 /**
  * @inheritDoc
  */
 public function render($content = null)
 {
     if ($content === null) {
         if (!isset($this->parts['{beginWrapper'])) {
             $options = $this->wrapperOptions;
             $tag = ArrayHelper::remove($options, 'tag', 'div');
             $this->parts['{beginWrapper}'] = Html::beginTag($tag, $options);
             $this->parts['{endWrapper}'] = Html::endTag($tag);
         }
         if ($this->label === false) {
             $this->parts['{label}'] = '';
             $this->parts['{beginLabel}'] = '';
             $this->parts['{labelTitle}'] = '';
             $this->parts['{endLabel}'] = '';
         } elseif (!isset($this->parts['{beginLabel'])) {
             $this->parts['{beginLabel}'] = Html::beginTag('label', $this->labelOptions);
             $this->parts['{endLabel}'] = Html::endTag('label');
             $attribute = Html::getAttributeName($this->attribute);
             $this->parts['{labelTitle}'] = Html::encode($this->label ? $this->label : $this->model->getAttributeLabel($attribute));
         }
         if ($this->inputTemplate) {
             $input = isset($this->parts['{input}']) ? $this->parts['{input}'] : Html::activeTextInput($this->model, $this->attribute, $this->inputOptions);
             $this->parts['{input}'] = strtr($this->inputTemplate, ['{input}' => $input]);
         }
     }
     return parent::render($content);
 }
 public function render($content = null)
 {
     if (!isset($this->parts['{hider}'])) {
         $this->parts['{hider}'] = "<a href='#' style = 'margin-top:2px;margin-bottom:2px;\n\t\tfloat: right;padding-right: 4px;padding-left: 5px;padding-top: 2px;padding-bottom: 0px'\n\t \tclass = 'btn btn-default put-on-cloak' value = {$this->attribute}><span style = 'color:#C0C0C0' class = 'glyphicon glyphicon-remove' ></a>";
     }
     return parent::render();
 }
Example #3
0
 public function render($content = null)
 {
     if (!isset($this->parts['{hint}']) || $this->parts['{hint}'] === null) {
         $this->template = str_replace("\n{hint}", '', $this->template);
     }
     $this->prepareTemplate();
     return parent::render($content);
 }
 /**
  * @param null $content
  * @return string
  */
 public function render($content = null)
 {
     if ($content === null) {
         if (!isset($this->parts['{icon}'])) {
             $this->parts['{icon}'] = '';
         }
     }
     return parent::render($content);
 }
Example #5
0
    /**
     * @todo    discuss|review  Expected HTML shouldn't be wrapped only by the $content?
     */
    public function testRenderWithCallableContent()
    {
        // field will be the html of the model's attribute wrapped with the return string below.
        $field = $this->attributeName;
        $content = function ($field) {
            return "<div class=\"custom-container\"> {$field} </div>";
        };
        $expectedValue = <<<EOD
<div class="form-group field-dynamicmodel-attributename">
<div class="custom-container"> <div class="form-group field-dynamicmodel-attributename">
<label class="control-label" for="dynamicmodel-attributename">Attribute Name</label>
<input type="text" id="dynamicmodel-attributename" class="form-control" name="DynamicModel[{$this->attributeName}]">

<div class="help-block"></div>
</div> </div>
</div>
EOD;
        $actualValue = $this->activeField->render($content);
        $this->assertEqualsWithoutLE($expectedValue, $actualValue);
    }
 public function render($content = null)
 {
     $label = $this->model->getAttributeLabel($this->attribute);
     $this->html = ArrayHelper::merge(['caption' => $label], $this->html);
     $this->inputOptions['placeholder'] = $this->inputOptions['placeholder'] ? $this->inputOptions['placeholder'] : $label;
     $this->html['attr'] = $this->html['attr'] ? $this->html['attr'] . " placeholder='{$this->inputOptions['placeholder']}'" : "placeholder='{$this->inputOptions['placeholder']}'";
     if ($this->form->autogenerate) {
         return '';
     }
     $this->parts['{error}'] = '';
     return parent::render($content);
 }
Example #7
0
 public function render($content = null)
 {
     $this->adaptField();
     $this->processPrependAndAppend();
     return parent::render($content);
 }
 public function render($content = null)
 {
     $this->inputOptions['placeholder'] = is_null($this->inputOptions['placeholder']) ? $this->model->getAttributeLabel($this->attribute) : null;
     $this->registerStyles();
     return parent::render($content);
 }
 /**
  * @inheritdoc
  */
 public function render($content = null)
 {
     if ($content === null) {
         if ($this->enableLabel === false) {
             $this->parts['{label}'] = '';
             $this->parts['{beginLabel}'] = '';
             $this->parts['{labelTitle}'] = '';
             $this->parts['{endLabel}'] = '';
         } elseif (!isset($this->parts['{beginLabel}'])) {
             $this->renderLabelParts();
         }
         if ($this->enableError === false) {
             $this->parts['{error}'] = '';
         }
         if ($this->inputTemplate) {
             $input = isset($this->parts['{input}']) ? $this->parts['{input}'] : Html::activeTextInput($this->model, $this->attribute, $this->inputOptions);
             $this->parts['{input}'] = strtr($this->inputTemplate, ['{input}' => $input]);
         }
     }
     return parent::render($content);
 }
 /**
  * @inheritdoc
  */
 public function render($content = null)
 {
     if ($content === null) {
         if (!isset($this->parts['{beginWrapper}'])) {
             $options = $this->wrapperOptions;
             $tag = ArrayHelper::remove($options, 'tag', 'div');
             $this->parts['{beginWrapper}'] = Html::beginTag($tag, $options);
             $this->parts['{endWrapper}'] = Html::endTag($tag);
         }
         if ($this->enableLabel === false) {
             $this->parts['{label}'] = '';
             $this->parts['{beginLabel}'] = '';
             $this->parts['{labelTitle}'] = '';
             $this->parts['{endLabel}'] = '';
         } elseif (!isset($this->parts['{beginLabel}'])) {
             $this->renderLabelParts();
         }
         if ($this->enableError === false) {
             $this->parts['{error}'] = '';
         }
         if ($this->inputTemplate) {
             $input = isset($this->parts['{input}']) ? $this->parts['{input}'] : Html::activeTextInput($this->model, $this->attribute, $this->inputOptions);
             $this->parts['{input}'] = strtr($this->inputTemplate, ['{input}' => $input]);
         }
     }
     return parent::render($content);
 }
 /**
  * @inheritdoc
  */
 public function render($content = null)
 {
     if ($this->getConfigParam('showHints') === false) {
         $this->hintOptions['hint'] = '';
     } else {
         if ($content === null && !isset($this->parts['{hint}']) && !isset($this->hintOptions['hint'])) {
             $this->hintOptions['hint'] = $this->generateHint();
         }
         $this->template = strtr($this->template, ['{hint}' => $this->_settings['hint']]);
     }
     if ($this->form->staticOnly === true) {
         $this->buildTemplate();
         $this->staticInput();
     } else {
         $this->initPlaceholder($this->inputOptions);
         $this->initDisability($this->inputOptions);
         $this->buildTemplate();
     }
     return parent::render($content);
 }
 public function render($content = null)
 {
     $this->registerStyles();
     return parent::render($content);
 }
Example #13
0
 /**
  * @inherit doc
  */
 public function render($content = null)
 {
     if ($this->form->staticOnly === true) {
         $field = $this->staticInput();
         $this->initTemplate();
         $this->buildTemplate();
         return parent::render(null);
     }
     $this->initTemplate();
     $this->initPlaceholder($this->inputOptions);
     $this->initAddon();
     $this->initDisability($this->inputOptions);
     $this->buildTemplate();
     return parent::render($content);
 }
Example #14
0
 /**
  * @inheritdoc
  */
 public function render($content = null)
 {
     if ($content === null) {
         $this->_renderWrapper();
         $this->_renderIcon();
         $this->_renderTooltip();
         if (!isset($this->parts['{input}'])) {
             $this->textInput();
         }
     }
     return parent::render($content);
 }
 /**
  * @inheritdoc
  */
 public function render($content = null)
 {
     echo "here";
     if ($content === null) {
         if (!isset($this->parts['{beginWrapper}'])) {
             $options = $this->wrapperOptions;
             $tag = ArrayHelper::remove($options, 'tag', 'div');
             $this->parts['{beginWrapper}'] = Html::beginTag($tag, $options);
             $this->parts['{endWrapper}'] = Html::endTag($tag);
         }
         if ($this->enableLabel === false) {
             $this->parts['{label}'] = '';
             $this->parts['{beginLabel}'] = '';
             $this->parts['{labelTitle}'] = '';
             $this->parts['{endLabel}'] = '';
         } elseif (!isset($this->parts['{beginLabel}'])) {
             $this->renderLabelParts();
         }
         if ($this->enableError === false) {
             $this->parts['{error}'] = '';
         }
         if ($this->inputTemplate) {
             $input = isset($this->parts['{input}']) ? $this->parts['{input}'] : Html::activeTextInput($this->model, $this->attribute, $this->inputOptions);
             $newInput = $this->contentBeforeInput . $this->generateAddon() . $this->contentAfterInput;
             var_dump($newInput);
             exit;
             $this->parts['{input}'] = strtr($this->inputTemplate, ['{input}' => $newInput]);
             //  $this->template = strtr($this->template, [
             //     '{input}' => str_replace('{input}', $newInput, $input),
             // ]);
         }
     }
     // $this->buildTemplate();
     //  $newInput = $this->contentBeforeInput . $this->generateAddon(). $this->contentAfterInput;
     //  $this->template = strtr($this->template, [
     //     '{input}' => str_replace('{input}', $newInput, $input),
     // ]);
     var_dump($content);
     return parent::render($content);
 }
Example #16
0
 /**
  * Renders the whole field.
  * This method will generate the label, error tag, input tag and hint tag (if any), and
  * assemble them into HTML according to [[template]].
  *
  * @param string|callable $content the content within the field container.
  * If null (not set), the default methods will be called to generate the label, error tag and input tag,
  * and use them as the content.
  * If a callable, it will be called to generate the content. The signature of the callable should be:
  *
  * ~~~
  * function ($field) {
  *     return $html;
  * }
  * ~~~
  *
  * @return string the rendering result
  */
 public function render($content = null)
 {
     $this->initTemplate();
     $this->initPlaceholder($this->inputOptions);
     $this->initAddon();
     return parent::render($content);
 }