Closed acobster closed 3 years ago
Slight adjustment - the correct logic is actually:
$value = $value ?: $field['default'] ?? $value;
This is because we do want ?:
to carry forward falsey values including null
, but we still need the ?? $value
after in case $value
is falsey AND the default is not set.
Expected behavior
Say you have a field
my_field
with a value of"0"
:Assuming you declare this field server-side in your form class, you might expect that if the user checks that input, you'd get this:
Actual behavior
Instead, you get
null
because of the more lenient?:
operator in thefilter_field()
method:"0"
is falsey, so the field value is falling back to the field default, if it exists, and otherwise tonull
. We should honor any non-null value here by using the??
operator instead of?:
.