*/
protected $templateName = '__selectFormField';
- /**
- * @inheritDoc
- */
- public function getSaveValue()
- {
- if ($this->getValue() === '') {
- return;
- }
-
- return parent::getSaveValue();
- }
-
/**
* @inheritDoc
*/
$value = $this->getDocument()->getRequestData($this->getPrefixedId());
if (\is_string($value)) {
- $this->value = $value;
+ $this->value = $value !== '' ? $value : null;
}
}
*/
public function validate()
{
- if ($this->getValue() === '') {
+ if ($this->getValue() === null) {
if ($this->isRequired()) {
$this->addValidationError(new FormFieldValidationError('empty'));
}
*/
public function value($value)
{
- // ignore `null` as value which can be passed either for nullable
- // fields or as value if no options are available
- if ($value === null) {
- return $this;
- }
-
- if (!isset($this->getOptions()[$value])) {
- throw new \InvalidArgumentException("Unknown value '{$value}' for field '{$this->getId()}'.");
+ if ($value !== null) {
+ if (!isset($this->getOptions()[$value])) {
+ throw new \InvalidArgumentException("Unknown value '{$value}' for field '{$this->getId()}'.");
+ }
}
return parent::value($value);