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
There is no way to map the shape of the data returned by a form submit event before it got passed to the validator. We could either validate the flat structure and map it after validating but before posting, but we decided to allow a transform function as part of the form that runs on the data before validation. We solved it with the following code:
exportconstdeepenFlatObject=(data: object): object=>{returnObject.entries(data).reduce((acc,[key,value])=>{constpath=key.split(".");lettarget=acc;for(leti=0;i<path.length-1;i++){constkey=path[i];constisArray=/^\d+$/.test(path[i+1]);target[key]??=isArray ? [] : {};target=target[key];}// biome-ignore lint/style/noNonNullAssertion: Last item is always definedtarget[path.at(-1)!]=value;returnacc;// biome-ignore lint/suspicious/noExplicitAny: We know what we're doing},{}asany);};
It would be nice if we had a standard implementation for this in the template.
The text was updated successfully, but these errors were encountered:
I'm unsure if this is something we actually want to happen in forms? This is what react-zorm did for us, but that package had its issues so we moved away from it.
As for a implementation, we might want to depend on dot-object, which does this (among other things) and is a little more battle-tested.
Onbezorgd Ontslag backend has a POSt route that requires data in a certain shape:
There is no way to map the shape of the data returned by a form submit event before it got passed to the validator. We could either validate the flat structure and map it after validating but before posting, but we decided to allow a
transform
function as part of theform
that runs on the data before validation. We solved it with the following code:It would be nice if we had a standard implementation for this in the template.
The text was updated successfully, but these errors were encountered: