radio() public method

This method will generate the checked tag attribute according to the model attribute value.
public radio ( 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 radio button. 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 radio button 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 radio within the label. If `true`, the method will still use [[template]] to layout the radio button and the error message except that the radio is enclosed by the label tag.
 /**
  * @inheritdoc
  */
 public function radio($options = [], $enclosedByLabel = false)
 {
     $this->template = $this->form->layout === 'inline' ? $this->inlineTemplate : $this->radioTemplate;
     return parent::radio($options, $enclosedByLabel);
 }
Beispiel #2
0
 /**
  * Renders a radio button.
  * 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 radio button.  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 radio button 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 radio within the label.
  * If true, the method will still use [[template]] to layout the checkbox and the error message
  * except that the radio is enclosed by the label tag.
  * @return ActiveField object
  */
 public function radio($options = [], $enclosedByLabel = true)
 {
     $this->_offset = true;
     return parent::radio($options, $enclosedByLabel);
 }
 /**
  * @inheritdoc
  */
 public function radio($options = [], $enclosedByLabel = true)
 {
     if ($enclosedByLabel) {
         if (!isset($options['template'])) {
             $this->template = $this->form->layout === 'horizontal' ? $this->horizontalRadioTemplate : $this->radioTemplate;
         } 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::radio($options, false);
 }
Beispiel #4
0
 /**
  * @inheritdoc
  */
 public function radio($options = [], $enclosedByLabel = true)
 {
     $this->setInlineTemplate();
     Html::addCssClass($this->options, 'form-group--radio-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-radio'] = true;
     $this->beforeRenderInput(__METHOD__, $options);
     return parent::radio($options, $enclosedByLabel);
 }