function ChoiceFormField::setValue
Sets the value of the field.
Throws
\InvalidArgumentException When value type provided is not correct
Overrides FormField::setValue
3 calls to ChoiceFormField::setValue()
- ChoiceFormField::select in vendor/
symfony/ dom-crawler/ Field/ ChoiceFormField.php - Sets the value of the field.
- ChoiceFormField::tick in vendor/
symfony/ dom-crawler/ Field/ ChoiceFormField.php - Ticks a checkbox.
- ChoiceFormField::untick in vendor/
symfony/ dom-crawler/ Field/ ChoiceFormField.php - Unticks a checkbox.
File
-
vendor/
symfony/ dom-crawler/ Field/ ChoiceFormField.php, line 102
Class
- ChoiceFormField
- ChoiceFormField represents a choice form field.
Namespace
Symfony\Component\DomCrawler\FieldCode
public function setValue(string|array|bool|null $value) : void {
if ('checkbox' === $this->type && false === $value) {
// uncheck
$this->value = null;
}
elseif ('checkbox' === $this->type && true === $value) {
// check
$this->value = $this->options[0]['value'];
}
else {
if (\is_array($value)) {
if (!$this->multiple) {
throw new \InvalidArgumentException(\sprintf('The value for "%s" cannot be an array.', $this->name));
}
foreach ($value as $v) {
if (!$this->containsOption($v, $this->options)) {
throw new \InvalidArgumentException(\sprintf('Input "%s" cannot take "%s" as a value (possible values: "%s").', $this->name, $v, implode('", "', $this->availableOptionValues())));
}
}
}
elseif (!$this->containsOption($value, $this->options)) {
throw new \InvalidArgumentException(\sprintf('Input "%s" cannot take "%s" as a value (possible values: "%s").', $this->name, $value, implode('", "', $this->availableOptionValues())));
}
if ($this->multiple) {
$value = (array) $value;
}
if (\is_array($value)) {
$this->value = $value;
}
else {
parent::setValue($value);
}
}
}