checkbox() public method

This method will generate the checked tag attribute according to the model attribute value.
public checkbox ( array $options = [], boolean $enclosedByLabel = true )
$options array the tag options in terms of name-value pairs. The following options are specially handled: - `uncheck`: string, the value associated with the uncheck state of the radio button. If not set, it will take the default value `0`. This method will render a hidden input so that if the radio button is not checked and is submitted, the value of this attribute will still be submitted to the server via the hidden input. If you do not want any hidden input, you should explicitly set this option as `null`. - `label`: string, a label displayed next to the checkbox. It will NOT be HTML-encoded. Therefore you can pass in HTML code such as an image tag. If this is coming from end users, you should [[Html::encode()|encode]] it to prevent XSS attacks. When this option is specified, the checkbox will be enclosed by a label tag. If you do not want any label, you should explicitly set this option as `null`. - `labelOptions`: array, the HTML attributes for the label tag. This is only used when the `label` option is specified. The rest of the options will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [[Html::encode()]]. If a value is `null`, the corresponding attribute will not be rendered. If you set a custom `id` for the input element, you may need to adjust the [[$selectors]] accordingly.
$enclosedByLabel boolean whether to enclose the checkbox within the label. If `true`, the method will still use [[template]] to layout the checkbox and the error message except that the checkbox is enclosed by the label tag.
 /**
  * Renders switcher
  * @see http://materializecss.com/forms.html#switches
  * @param array $options
  * @param array $flags
  * @return $this
  */
 public function switcher($options = [], $flags = null)
 {
     parent::checkbox($options, false);
     if ($flags === null) {
         $label = Html::encode($this->model->getAttributeLabel(Html::getAttributeName($this->attribute)));
         $labelParts = explode(',', $label);
         $flags = count($labelParts) >= 2 ? $labelParts : null;
     }
     if ($flags) {
         Html::removeCssClass($this->options, 'input-field');
         Html::addCssClass($this->options, 'switch');
         $labelContent = $flags[0] . $this->parts['{input}'] . Html::tag('span', '', ['class' => 'lever']) . $flags[1];
         $this->parts['{input}'] = Html::label($labelContent, Html::getInputId($this->model, $this->attribute));
     }
     return $this;
 }
Example #2
0
 /**
  * @inheritdoc
  */
 public function checkbox($options = [], $enclosedByLabel = true)
 {
     if (isset($this->inputOptions['name'])) {
         $options['name'] = $this->inputOptions['name'];
     }
     return parent::checkbox($options, $enclosedByLabel);
 }
 /**
  * @inheritdoc
  */
 public function checkbox($options = [], $enclosedByLabel = false)
 {
     if ($enclosedByLabel) {
         $this->template = $this->form->layout === 'inline' ? $this->inlineTemplate : $this->checkboxTemplate;
     }
     $this->template = $this->checkboxTemplate;
     return parent::checkbox($options, $enclosedByLabel);
 }
 /**
  * @inheritdoc
  */
 public function checkbox($options = [], $enclosedByLabel = true)
 {
     if ($enclosedByLabel) {
         if (!isset($options['template'])) {
             $this->template = $this->form->layout === 'horizontal' ? $this->horizontalCheckboxTemplate : $this->checkboxTemplate;
         } else {
             $this->template = $options['template'];
             unset($options['template']);
         }
         if ($this->form->layout === 'horizontal') {
             Html::addCssClass($this->wrapperOptions, $this->horizontalCssClasses['offset']);
         }
         $this->labelOptions['class'] = null;
     }
     return parent::checkbox($options, false);
 }
Example #5
0
 public function checkbox($options = [], $enclosedByLabel = true)
 {
     $options = array_merge($this->inputOptions, $options);
     return parent::checkbox($options, $enclosedByLabel);
 }
Example #6
0
 public function checkbox($options = [], $enclosedByLabel = false)
 {
     parent::checkbox($options, $enclosedByLabel);
     return $this;
 }
Example #7
0
 /**
  * Skip \kartik\form\ActiveField::checkbox()
  * @see \kartik\form\ActiveField::checkbox()
  */
 public function checkbox($options = [], $enclosedByLabel = true)
 {
     return grandParent::checkbox($options, $enclosedByLabel);
 }
Example #8
0
 /**
  * @inheritdoc
  */
 public function checkbox($options = [], $enclosedByLabel = true)
 {
     if ($enclosedByLabel) {
         if (!isset($options['template'])) {
             if ($this->form->layout === 'horizontal') {
                 $this->template = "{beginWrapper}\n<div class=\"checkbox\">\n{beginLabel}\n{input}\n{labelTitle}\n{endLabel}\n</div>\n{error}\n{endWrapper}\n{hint}";
                 Html::addCssClass($this->wrapperOptions, $this->horizontalCssClasses['offset']);
             } else {
                 $this->template = "<div class=\"checkbox\">\n{beginLabel}\n{input}\n{labelTitle}\n{endLabel}\n{error}\n{hint}\n</div>";
             }
         } else {
             $this->template = $options['template'];
             unset($options['template']);
         }
         $this->labelOptions['class'] = null;
     }
     parent::checkbox($options, false);
     return $this;
 }
Example #9
0
 /**
  * @inheritdoc
  */
 public function switchInput($options = [], $enclosedByLabel = true)
 {
     if ($enclosedByLabel) {
         if (!isset($options['template'])) {
             $this->template = $this->switchTemplate;
         } else {
             $this->template = $options['template'];
             unset($options['template']);
         }
         $this->labelOptions['class'] = null;
     }
     return parent::checkbox($options, false);
 }
Example #10
0
 /**
  * @inheritdoc
  */
 public function checkbox($options = [], $enclosedByLabel = true)
 {
     $this->checkboxTemplate = "{input}\n{beginLabel}\n{labelTitle}\n{endLabel}";
     //$this->options['class'] = null;
     if ($enclosedByLabel) {
         if (!isset($options['template'])) {
             $this->template = $this->form->layout === 'horizontal' ? $this->horizontalCheckboxTemplate : $this->checkboxTemplate;
         } else {
             $this->template = $options['template'];
             unset($options['template']);
         }
         if (isset($options['label'])) {
             $this->parts['{labelTitle}'] = $options['label'];
         }
         if ($this->form->layout === 'horizontal') {
             Html::addCssClass($this->wrapperOptions, $this->horizontalCssClasses['offset']);
         }
         //$this->labelOptions['class'] = null;
     }
     return parent::checkbox($options, false);
 }
Example #11
0
 /**
  * Renders a checkbox.
  * This method will generate the "checked" tag attribute according to the model attribute value.
  * @param array $options the tag options in terms of name-value pairs. The following options are specially handled:
  *
  * - uncheck: string, the value associated with the uncheck state of the radio button. If not set,
  *   it will take the default value '0'. This method will render a hidden input so that if the radio button
  *   is not checked and is submitted, the value of this attribute will still be submitted to the server
  *   via the hidden input. If you do not want any hidden input, you should explicitly set this option as null.
  * - label: string, a label displayed next to the checkbox. It will NOT be HTML-encoded. Therefore you can pass
  *   in HTML code such as an image tag. If this is coming from end users, you should [[Html::encode()|encode]] it to prevent XSS attacks.
  *   When this option is specified, the checkbox will be enclosed by a label tag. If you do not want any label, you should
  *   explicitly set this option as null.
  * - labelOptions: array, the HTML attributes for the label tag. This is only used when the "label" option is specified.
  *
  * The rest of the options will be rendered as the attributes of the resulting tag. The values will
  * be HTML-encoded using [[Html::encode()]]. If a value is null, the corresponding attribute will not be rendered.
  *
  * If you set a custom `id` for the input element, you may need to adjust the [[$selectors]] accordingly.
  *
  * @param boolean $enclosedByLabel whether to enclose the checkbox within the label.
  * If true, the method will still use [[template]] to layout the checkbox and the error message
  * except that the checkbox is enclosed by the label tag.
  * @return static the field object itself
  */
 public function checkbox($options = [], $enclosedByLabel = true)
 {
     if ($enclosedByLabel && $this->form->isHorizontal) {
         $this->parts['{input}'] = Html::activeCheckbox($this->model, $this->attribute, $options);
         $this->parts['{label}'] = '<div class="col-md-2"></div>';
         $this->adjustLabelFor($options);
         return $this;
     } else {
         return parent::checkbox($options, $enclosedByLabel);
     }
 }
Example #12
0
 /**
  * Renders a checkbox.
  * This method will generate the "checked" tag attribute according to the model attribute value.
  *
  * @param array $options the tag options in terms of name-value pairs. The following options are specially handled:
  * @param bool  $enclosedByLabel
  * @return $this the field object itself
  */
 public function checkbox($options = [], $enclosedByLabel = true)
 {
     return parent::checkbox($options, false);
 }
Example #13
0
 /**
  * Renders a checkbox.
  * This method will generate the "checked" tag attribute according to the model attribute value.
  *
  * @param array $options the tag options in terms of name-value pairs. The following options are specially handled:
  *
  * - uncheck: string, the value associated with the uncheck state of the radio button. If not set,
  *   it will take the default value '0'. This method will render a hidden input so that if the radio button
  *   is not checked and is submitted, the value of this attribute will still be submitted to the server
  *   via the hidden input.
  * - label: string, a label displayed next to the checkbox.  It will NOT be HTML-encoded. Therefore you can pass
  *   in HTML code such as an image tag. If this is is coming from end users, you should [[Html::encode()]] it to prevent XSS attacks.
  *   When this option is specified, the checkbox will be enclosed by a label tag.
  * - labelOptions: array, the HTML attributes for the label tag. This is only used when the "label" option is specified.
  *
  * The rest of the options will be rendered as the attributes of the resulting tag. The values will
  * be HTML-encoded using [[Html::encode()]]. If a value is null, the corresponding attribute will not be rendered.
  * @param boolean $enclosedByLabel whether to enclose the checkbox within the label.
  * If true, the method will still use [[template]] to layout the checkbox and the error message
  * except that the checkbox is enclosed by the label tag.
  * @return ActiveField object
  */
 public function checkbox($options = [], $enclosedByLabel = true)
 {
     $this->_offset = true;
     return parent::checkbox($options, $enclosedByLabel);
 }
Example #14
0
 /**
  * @inheritdoc
  */
 public function checkbox($options = [], $enclosedByLabel = true)
 {
     $this->setInlineTemplate();
     Html::addCssClass($this->options, 'form-group--checkbox-input');
     $options = array_merge($this->inputOptions, $options);
     $options['title'] = $this->model->getAttributeLabel($this->attribute);
     $options['ng-model'] = ArrayHelper::remove($options, 'ng-model', sprintf('data.%s', $this->attribute));
     $options['ng-custom-checkbox'] = true;
     $this->beforeRenderInput(__METHOD__, $options);
     return parent::checkbox($options, $enclosedByLabel);
 }