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
I think the most explicit and straightforward way would be:
constEMPTY_VALUES_BY_COMPONENT_TYPE={textfield: '',numberfield: null,// file: [],editgrid: [],}asconst;typeEmptyValueKeys=keyoftypeofEMPTY_VALUES_BY_COMPONENT_TYPE;typeEmptyValueTypes=typeofEMPTY_VALUES_BY_COMPONENT_TYPE[EmptyValueKeys];constgetEmptyValueForComponent=(component: ComponentSchema): EmptyValueTypes|[]=>{// I *think* this should cover it in a generic way, but I'm not sure about exotic components like editgridif(component.multiple){return[];}if(!EMPTY_VALUES_BY_COMPONENT_TYPE[component.type]){thrownewError(`Ensure the component type ${component.type} is added to the mapping.`);}returnEMPTY_VALUES_BY_COMPONENT_TYPE[component.type];};
This keeps the data type uniform with the "not-empty value" datatype where possible
It's a simple lookup table
Empty value vs unset for a form is not a relevant distinction - it needs to normalize to a "string-like" thing for keyboard input anyway. For data processing in the backend it's also far easier to have the "guarantee" that the data type is always as expected. As for whether the input was touched/changed, a comparison against component.defaultValue should be sufficient (which is also what happens in the linked backend code).
Empty value vs unset for a form is not a relevant distinction - it needs to normalize to a "string-like" thing for keyboard input anyway. For data processing in the backend it's also far easier to have the "guarantee" that the data type is always as expected. As for whether the input was touched/changed, a comparison against
component.defaultValue
should be sufficient (which is also what happens in the linked backend code).Let's try this approach and see how far we get?
Originally posted by @sergei-maertens in #28 (comment)
The text was updated successfully, but these errors were encountered: