You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In HTML forms it seems there’s no way to properly submit an empty array. So instead of some blank value being submitted with the key, it just doesn’t get submitted at all. And unlike checkboxes with the hidden input you can place above them to ensure a default “off” value is submitted, with arrays there seem to be no such workarounds.
For our app, this is the best I could come up with for a schema where you really do want the array’s key to be present, so its nested validations can run:
This will be solved once we have support for types with default values. Then we can tweak Form::Array to be a default-value type having [] as the fallback value when nil was passed.
This sounds good. For our usage (which I think is a fairly reasonable approach for handling empty arrays in forms), I think we'd need dry-rb/dry-types#76 to be in place alongside this.
timriley
changed the title
Somehow support handling missing keys for empty array values in form schemas?
Support handling empty arrays in form schemas
Apr 13, 2016
In HTML forms it seems there’s no way to properly submit an empty array. So instead of some blank value being submitted with the key, it just doesn’t get submitted at all. And unlike checkboxes with the hidden input you can place above them to ensure a default “off” value is submitted, with arrays there seem to be no such workarounds.
For our app, this is the best I could come up with for a schema where you really do want the array’s key to be present, so its nested validations can run:
It would be nice if we could somehow support this kind of use case a little bit better with the form schemas.
The text was updated successfully, but these errors were encountered: