Skip to content

Commit 0a640e7

Browse files
dakorpardg
authored andcommitted
ChoiceControl, MultiChoiceControl: added checkDefaultValue() as replacement for $checkAllowedValues (#151)
1 parent 2867961 commit 0a640e7

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

src/Forms/Controls/ChoiceControl.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
*/
2121
abstract class ChoiceControl extends BaseControl
2222
{
23-
/** @var bool */
23+
/**
24+
* @var bool
25+
* @deprecated use checkDefaultValue()
26+
*/
2427
public $checkAllowedValues = true;
2528

2629
/** @var array */
@@ -147,4 +150,14 @@ public function setDisabled($value = true)
147150
}
148151
return $this;
149152
}
153+
154+
155+
/**
156+
* @return static
157+
*/
158+
public function checkDefaultValue(bool $value = true)
159+
{
160+
$this->checkAllowedValues = $value;
161+
return $this;
162+
}
150163
}

src/Forms/Controls/MultiChoiceControl.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
*/
2121
abstract class MultiChoiceControl extends BaseControl
2222
{
23-
/** @var bool */
23+
/**
24+
* @var bool
25+
* @deprecated use checkDefaultValue()
26+
*/
2427
public $checkAllowedValues = true;
2528

2629
/** @var array */
@@ -159,4 +162,14 @@ public function getHtmlName(): string
159162
{
160163
return parent::getHtmlName() . '[]';
161164
}
165+
166+
167+
/**
168+
* @return static
169+
*/
170+
public function checkDefaultValue(bool $value = true)
171+
{
172+
$this->checkAllowedValues = $value;
173+
return $this;
174+
}
162175
}

tests/Forms/Controls.ChoiceControl.loadData.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,10 @@ test(function () use ($series) { // setValue() and invalid argument
154154
});
155155

156156

157-
test(function () use ($series) { // setValue() and disabled $checkAllowedValues
157+
test(function () use ($series) { // setValue() and disabled checkDefaultValue()
158158
$form = new Form;
159159
$input = $form['select'] = new ChoiceControl(null, $series);
160-
$input->checkAllowedValues = false;
160+
$input->checkDefaultValue(false);
161161
$input->setValue('unknown');
162162
Assert::null($input->getValue());
163163
});

tests/Forms/Controls.MultiChoiceControl.loadData.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,10 @@ test(function () use ($series) { // setValue() and invalid argument
175175
});
176176

177177

178-
test(function () use ($series) { // setValue() and disabled $checkAllowedValues
178+
test(function () use ($series) { // setValue() and disabled checkDefaultValue()
179179
$form = new Form;
180180
$input = $form['select'] = new MultiChoiceControl(null, $series);
181-
$input->checkAllowedValues = false;
181+
$input->checkDefaultValue(false);
182182
$input->setValue('unknown');
183183
Assert::same([], $input->getValue());
184184

0 commit comments

Comments
 (0)