Closed maartendekeizer closed 2 years ago
Thanks for the report @maartendekeizer, #416 should fix this.
@kbond Tried #416, it works for the situation where the payload value is null, but when a empty string is submitted I still got an error Expected argument of type "?App\Enum\MyEnum", "string" given at property path "myField".
I think an empty string is submitted when the user touched the input/select but did cleared the value afterwards.
Got it, I'll adjust my PR to account for this.
it works for the situation where the payload value is null, but when a empty string is submitted I still got an error
@kbond yes, thanks a lot!
I created a component with 2 writeable live props, both nullable and with a BackedEnumType. When I changed a value a sync is happen as expected, but this will result in an error when one of the fields are empty
With request payload
{"data":1,"newPriority":null,"newStatus":"new","_checksum":"***"}
the following error occuredThe data is neither an integer nor a string, you should pass an integer or a string that can be parsed as an enumeration case of type App\Enum\Priority.
And with request payload
{"data":1,"newPriority":"high","newStatus":"","_checksum":"***"}
the following error occured"" is not a valid backing value for enum "App\Enum\Priority"
It think this is caused by the fact that the hydrator always try to denormalize and that empty strings are not converted to null values. https://github.com/symfony/ux/blob/ebe425c03d03643ab76080ee2860e019443b4d6e/src/LiveComponent/src/LiveComponentHydrator.php#L170-L175
A suggestion for the fix
Component
Template