Skip to content

Commit 6bc3a29

Browse files
committed
ChoiceControl, MultiChoiceControl::$checkAllowedValues removed, use checkDefaultValue()
1 parent acf270f commit 6bc3a29

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

src/Forms/Controls/ChoiceControl.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,8 @@
2020
*/
2121
abstract class ChoiceControl extends BaseControl
2222
{
23-
/**
24-
* @var bool
25-
* @deprecated use checkDefaultValue()
26-
*/
27-
public $checkAllowedValues = true;
23+
/** @var bool */
24+
private $checkDefaultValue = true;
2825

2926
/** @var array */
3027
private $items = [];
@@ -63,7 +60,7 @@ public function loadHttpData(): void
6360
*/
6461
public function setValue($value)
6562
{
66-
if ($this->checkAllowedValues && $value !== null && !array_key_exists((string) $value, $this->items)) {
63+
if ($this->checkDefaultValue && $value !== null && !array_key_exists((string) $value, $this->items)) {
6764
$set = Nette\Utils\Strings::truncate(implode(', ', array_map(function ($s) { return var_export($s, true); }, array_keys($this->items))), 70, '...');
6865
throw new Nette\InvalidArgumentException("Value '$value' is out of allowed set [$set] in field '{$this->name}'.");
6966
}
@@ -157,7 +154,7 @@ public function setDisabled($value = true)
157154
*/
158155
public function checkDefaultValue(bool $value = true)
159156
{
160-
$this->checkAllowedValues = $value;
157+
$this->checkDefaultValue = $value;
161158
return $this;
162159
}
163160
}

src/Forms/Controls/MultiChoiceControl.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,8 @@
2020
*/
2121
abstract class MultiChoiceControl extends BaseControl
2222
{
23-
/**
24-
* @var bool
25-
* @deprecated use checkDefaultValue()
26-
*/
27-
public $checkAllowedValues = true;
23+
/** @var bool */
24+
private $checkDefaultValue = true;
2825

2926
/** @var array */
3027
private $items = [];
@@ -71,7 +68,7 @@ public function setValue($values)
7168
$flip[(string) $value] = true;
7269
}
7370
$values = array_keys($flip);
74-
if ($this->checkAllowedValues && ($diff = array_diff($values, array_keys($this->items)))) {
71+
if ($this->checkDefaultValue && ($diff = array_diff($values, array_keys($this->items)))) {
7572
$set = Nette\Utils\Strings::truncate(implode(', ', array_map(function ($s) { return var_export($s, true); }, array_keys($this->items))), 70, '...');
7673
$vals = (count($diff) > 1 ? 's' : '') . " '" . implode("', '", $diff) . "'";
7774
throw new Nette\InvalidArgumentException("Value$vals are out of allowed set [$set] in field '{$this->name}'.");
@@ -169,7 +166,7 @@ public function getHtmlName(): string
169166
*/
170167
public function checkDefaultValue(bool $value = true)
171168
{
172-
$this->checkAllowedValues = $value;
169+
$this->checkDefaultValue = $value;
173170
return $this;
174171
}
175172
}

0 commit comments

Comments
 (0)