Skip to content

Commit 03085f9

Browse files
author
Eugene Tupikov
committed
set default value for uncheck and unselect options if they not set via property options
1 parent 9187d23 commit 03085f9

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

examples/models/ExampleModel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ public function init()
4747
'day' => '27.02.2015',
4848
'user_id' => 31,
4949
'priority' => 1,
50-
'enable' => true
50+
'enable' => 1
5151
],
5252
[
5353
'day' => '27.02.2015',
5454
'user_id' => 33,
5555
'priority' => 2,
56-
'enable' => false
56+
'enable' => 0
5757
],
5858
];
5959
}

examples/views/multiple-input.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
<?php $form = ActiveForm::begin([
1818
'enableAjaxValidation' => true,
19-
// 'enableAjaxValidation' => false,
2019
'enableClientValidation' => false,
2120
'validateOnChange' => false,
2221
'validateOnSubmit' => true,
@@ -93,11 +92,20 @@
9392
]
9493
],
9594
[
96-
'type' => 'checkbox',
95+
'type' => MultipleInputColumn::TYPE_CHECKBOX_LIST,
9796
'name' => 'enable',
98-
'defaultValue' => 0,
9997
'headerOptions' => [
100-
'style' => 'width: 20px;',
98+
'style' => 'width: 80px;',
99+
],
100+
'items' => [
101+
1 => 'Test 1',
102+
2 => 'Test 2',
103+
3 => 'Test 3',
104+
4 => 'Test 4'
105+
],
106+
'options' => [
107+
// see checkboxList implementation in the BaseHtml helper for getting more detail
108+
'unselect' => 2
101109
]
102110
]
103111
]

src/components/BaseColumn.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ abstract class BaseColumn extends Object
5757
/**
5858
* @var mixed default value for input
5959
*/
60-
public $defaultValue = '';
60+
public $defaultValue;
6161

6262
/**
6363
* @var array
@@ -272,6 +272,9 @@ protected function renderRadio($name, $value, $options)
272272
if (!isset($options['label'])) {
273273
$options['label'] = '';
274274
}
275+
if (!array_key_exists('uncheck', $options)) {
276+
$options['uncheck'] = 0;
277+
}
275278
$input = Html::radio($name, $value, $options);
276279
return Html::tag('div', $input, ['class' => 'radio']);
277280
}
@@ -284,11 +287,14 @@ protected function renderRadio($name, $value, $options)
284287
*/
285288
protected function renderRadioList($name, $value, $options)
286289
{
290+
if (!array_key_exists('unselect', $options)) {
291+
$options['unselect'] = '';
292+
}
287293
$options['item'] = function ($index, $label, $name, $checked, $value) {
288294
return '<div class="radio">' . Html::radio($name, $checked, ['label' => $label, 'value' => $value]) . '</div>';
289295
};
290296
$input = Html::radioList($name, $value, $this->items, $options);
291-
return Html::tag('div', $input, ['class' => 'radio']);
297+
return Html::tag('div', $input, ['class' => 'radio-list']);
292298
}
293299

294300
/**
@@ -302,6 +308,9 @@ protected function renderCheckbox($name, $value, $options)
302308
if (!isset($options['label'])) {
303309
$options['label'] = '';
304310
}
311+
if (!array_key_exists('uncheck', $options)) {
312+
$options['uncheck'] = 0;
313+
}
305314
$input = Html::checkbox($name, $value, $options);
306315
return Html::tag('div', $input, ['class' => 'checkbox']);
307316
}
@@ -314,11 +323,14 @@ protected function renderCheckbox($name, $value, $options)
314323
*/
315324
protected function renderCheckboxList($name, $value, $options)
316325
{
326+
if (!array_key_exists('unselect', $options)) {
327+
$options['unselect'] = '';
328+
}
317329
$options['item'] = function ($index, $label, $name, $checked, $value) {
318330
return '<div class="checkbox">' . Html::checkbox($name, $checked, ['label' => $label, 'value' => $value]) . '</div>';
319331
};
320332
$input = Html::checkboxList($name, $value, $this->items, $options);
321-
return Html::tag('div', $input, ['class' => 'checkbox']);
333+
return Html::tag('div', $input, ['class' => 'checkbox-list']);
322334
}
323335

324336
/**

0 commit comments

Comments
 (0)