radioList() public method

A radio button list is like a checkbox list, except that it only allows single selection. The selection of the radio buttons is taken from the value of the model attribute.
public radioList ( array $items, array $options = [] )
$items array the data item used to generate the radio buttons. The array values are the labels, while the array keys are the corresponding radio values.
$options array options (name => config) for the radio button list. For the list of available options please refer to the `$options` parameter of [[\yii\helpers\Html::activeRadioList()]].
コード例 #1
0
 /**
  * @inheritdoc
  */
 public function radioList($items, $options = [])
 {
     if ($this->inline) {
         if (!isset($options['template'])) {
             $this->template = $this->inlineRadioListTemplate;
         } else {
             $this->template = $options['template'];
             unset($options['template']);
         }
         if (!isset($options['itemOptions'])) {
             $options['itemOptions'] = ['labelOptions' => ['class' => 'radio-inline']];
         }
     } elseif (!isset($options['item'])) {
         $options['item'] = function ($index, $label, $name, $checked, $value) {
             return '<div class="radio">' . Html::radio($name, $checked, ['label' => $label, 'value' => $value]) . '</div>';
         };
     }
     parent::radioList($items, $options);
     return $this;
 }
コード例 #2
0
 /**
  * @inheritdoc
  */
 public function radioList($items, $options = [])
 {
     $this->template = $this->form->layout === 'inline' ? $this->inlineTemplate : $this->radioListTemplate;
     if (!isset($options['item'])) {
         $options['item'] = function ($index, $label, $name, $checked, $value) {
             return Html::radio($name, $checked, ['label' => $label, 'value' => $value]);
         };
     }
     parent::radioList($items, $options);
     return $this;
 }
コード例 #3
0
ファイル: ActiveField.php プロジェクト: pathman/yii2comm
 /**
  * @inheritdoc
  */
 public function radioList($items, $options = [])
 {
     if ($this->inline) {
         if (!isset($options['template'])) {
             $this->template = $this->inlineRadioListTemplate;
         } else {
             $this->template = $options['template'];
             unset($options['template']);
         }
         if (!isset($options['itemOptions'])) {
             $options['itemOptions'] = ['container' => false, 'labelOptions' => ['class' => 'radio-inline']];
         }
     }
     parent::radioList($items, $options);
     return $this;
 }
コード例 #4
0
ファイル: ActiveField.php プロジェクト: derkamerad/adminUI
 /**
  * @inheritdoc
  */
 public function radioList($items, $options = [])
 {
     if ($this->inline) {
         if (!isset($options['template'])) {
             $this->template = "{label}\n{beginWrapper}\n{input}\n{error}\n{endWrapper}\n{hint}";
         } else {
             $this->template = $options['template'];
             unset($options['template']);
         }
         if (!isset($options['itemOptions'])) {
             $options['itemOptions'] = ['container' => false, 'labelOptions' => ['class' => 'radio-inline']];
         }
     }
     parent::radioList($items, $options);
     return $this;
 }
コード例 #5
0
ファイル: ActiveField.php プロジェクト: CBETOBuT/yii2-widgets
 /**
  * Renders a list of radio buttons.
  * A radio button list is like a checkbox list, except that it only allows single selection.
  * The selection of the radio buttons is taken from the value of the model attribute.
  *
  * @param array $items the data item used to generate the radio buttons.
  * The array keys are the labels, while the array values are the corresponding radio button values.
  * Note that the labels will NOT be HTML-encoded, while the values will.
  * @param array $options options (name => config) for the radio button list. The following options are specially handled:
  *
  * - unselect: string, the value that should be submitted when none of the radio buttons is selected.
  *   By setting this option, a hidden input will be generated.
  * - separator: string, the HTML code that separates items.
  * - inline: boolean, whether the list should be displayed as a series on the same line, default is false
  * - item: callable, a callback that can be used to customize the generation of the HTML code
  *   corresponding to a single item in $items. The signature of this callback must be:
  *
  * ~~~
  * function ($index, $label, $name, $checked, $value)
  * ~~~
  *
  * where $index is the zero-based index of the radio button in the whole list; $label
  * is the label for the radio button; and $name, $value and $checked represent the name,
  * value and the checked status of the radio button input.
  * @return ActiveField object
  */
 public function radioList($items, $options = [])
 {
     if (isset($options['inline']) && $options['inline'] == true) {
         Html::addCssClass($options['itemOptions']['labelOptions'], self::TYPE_RADIO . '-' . self::STYLE_INLINE);
         $options['itemOptions']['container'] = false;
         unset($options['inline']);
     }
     return parent::radioList($items, $options);
 }
コード例 #6
0
ファイル: ActiveField.php プロジェクト: cookyii/base
 /**
  * @inheritdoc
  */
 public function radioList($items, $options = [], $item_options = [])
 {
     $this->setInlineTemplate();
     Html::addCssClass($this->options, 'form-group--radio-list-input');
     $options = array_merge($this->inputOptions, $options);
     $options['item'] = ArrayHelper::remove($options, 'item', function ($index, $label, $name, $checked, $value) use($item_options) {
         $options = ['value' => $value, 'label' => Html::tag('span', $label), 'ng-custom-radio' => true, 'ng-model' => ArrayHelper::remove($item_options, 'ng-model', sprintf('data.%s', $this->attribute))];
         if (isset($item_options[$value])) {
             $options = array_merge($options, $item_options[$value]);
         }
         return Html::radio($name, $checked, $options);
     });
     Html::addCssClass($options, 'radio-list');
     $this->beforeRenderInput(__METHOD__, $options);
     return parent::radioList($items, $options);
 }
コード例 #7
-1
ファイル: ActiveField.php プロジェクト: sym660/lulucms2
 public function radioList($items, $options = [])
 {
     $options['tag'] = 'ul';
     $inputId = Html::getInputId($this->model, $this->attribute);
     $this->selectors = ['input' => "#{$inputId} input"];
     $options['class'] = 'da-form-list inline';
     $encode = !isset($options['encode']) || $options['encode'];
     $itemOptions = isset($options['itemOptions']) ? $options['itemOptions'] : [];
     $options['item'] = function ($index, $label, $name, $checked, $value) use($encode, $itemOptions) {
         $radio = Html::radio($name, $checked, array_merge($itemOptions, ['value' => $value, 'label' => $encode ? Html::encode($label) : $label]));
         return '<li>' . $radio . '</li>';
     };
     return parent::radioList($items, $options);
 }