checkboxList() public method

A checkbox list allows multiple selection, like ActiveField::listBox. As a result, the corresponding submitted value is an array. The selection of the checkbox list is taken from the value of the model attribute.
public checkboxList ( array $items, array $options = [] )
$items array the data item used to generate the checkboxes. The array values are the labels, while the array keys are the corresponding checkbox values.
$options array options (name => config) for the checkbox list. For the list of available options please refer to the `$options` parameter of [[\yii\helpers\Html::activeCheckboxList()]].
示例#1
0
 public function checkboxList($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) {
         $checkbox = Html::checkbox($name, $checked, array_merge($itemOptions, ['value' => $value, 'label' => $encode ? Html::encode($label) : $label]));
         return '<li>' . $checkbox . '</li>';
     };
     return parent::checkboxList($items, $options);
 }
 /**
  * @inheritdoc
  */
 public function checkboxList($items, $options = [])
 {
     $this->template = $this->form->layout === 'inline' ? $this->inlineTemplate : $this->checkboxListTemplate;
     if (!isset($options['item'])) {
         $options['item'] = function ($index, $label, $name, $checked, $value) {
             return Html::checkbox($name, $checked, ['label' => $label, 'value' => $value]);
         };
     }
     parent::checkboxList($items, $options);
     return $this;
 }
 /**
  * @inheritdoc
  */
 public function checkboxList($items, $options = [])
 {
     if ($this->inline) {
         if (!isset($options['template'])) {
             $this->template = $this->inlineCheckboxListTemplate;
         } else {
             $this->template = $options['template'];
             unset($options['template']);
         }
         if (!isset($options['itemOptions'])) {
             $options['itemOptions'] = ['labelOptions' => ['class' => 'checkbox-inline']];
         }
     } elseif (!isset($options['item'])) {
         $options['item'] = function ($index, $label, $name, $checked, $value) {
             return '<div class="checkbox">' . Html::checkbox($name, $checked, ['label' => $label, 'value' => $value]) . '</div>';
         };
     }
     parent::checkboxList($items, $options);
     return $this;
 }
示例#4
0
 /**
  * @inheritdoc
  */
 public function checkboxList($items, $options = [])
 {
     if ($this->inline) {
         if (!isset($options['template'])) {
             $this->template = $this->inlineCheckboxListTemplate;
         } else {
             $this->template = $options['template'];
             unset($options['template']);
         }
         if (!isset($options['itemOptions'])) {
             $options['itemOptions'] = ['container' => false, 'labelOptions' => ['class' => 'checkbox-inline']];
         }
     }
     parent::checkboxList($items, $options);
     return $this;
 }
示例#5
0
 /**
  * @inheritdoc
  */
 public function checkboxList($items, $options = [], $item_options = [])
 {
     $options['item'] = function ($index, $label, $name, $checked, $value) use($item_options) {
         $options = ['value' => $value, 'label' => $label, 'ng-model' => 'data.' . $this->attribute . '.' . $value];
         if (isset($item_options[$value])) {
             $options = array_merge($options, $item_options[$value]);
         }
         return Html::tag('md-checkbox', $label, $options);
     };
     return parent::checkboxList($items, $options);
 }
示例#6
0
 /**
  * @inheritdoc
  */
 public function checkboxList($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' => 'checkbox-inline']];
         }
     }
     parent::checkboxList($items, $options);
     return $this;
 }
示例#7
0
 /**
  * Renders a list of checkboxes.
  * A checkbox list allows multiple selection, like [[listBox()]].
  * As a result, the corresponding submitted value is an array.
  * The selection of the checkbox list is taken from the value of the model attribute.
  *
  * @param array $items the data item used to generate the checkboxes.
  * The array values are the labels, while the array keys are the corresponding checkbox values.
  * Note that the labels will NOT be HTML-encoded, while the values will.
  * @param array $options options (name => config) for the checkbox list. The following options are specially handled:
  *
  * - unselect: string, the value that should be submitted when none of the checkboxes 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 checkbox in the whole list; $label
  * is the label for the checkbox; and $name, $value and $checked represent the name,
  * value and the checked status of the checkbox input.
  * @return ActiveField object
  */
 public function checkboxList($items, $options = [])
 {
     if (isset($options['inline']) && $options['inline'] == true) {
         Html::addCssClass($options['itemOptions']['labelOptions'], self::TYPE_CHECKBOX . '-' . self::STYLE_INLINE);
         $options['itemOptions']['container'] = false;
         unset($options['inline']);
     }
     return parent::checkboxList($items, $options);
 }
示例#8
0
 /**
  * @inheritdoc
  */
 public function checkboxList($items, $options = [], $item_options = [])
 {
     $this->setInlineTemplate();
     Html::addCssClass($this->options, 'form-group--checkbox-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-checkbox' => true, 'ng-model' => ArrayHelper::remove($item_options, 'ng-model', sprintf('data.%s["%s"]', $this->attribute, $value))];
         if (isset($item_options[$value])) {
             $options = array_merge($options, $item_options[$value]);
         }
         return Html::checkbox($name, $checked, $options);
     });
     Html::addCssClass($options, 'checkbox-list');
     $this->beforeRenderInput(__METHOD__, $options);
     return parent::checkboxList($items, $options);
 }