I want to pass multiple functions for normalizing redux fields, is there a way to do so? like we pass a array in validation prop?
validate={[alphanumeric,maxlength]}
throughout redux-form questions i saw ways like
normalize={maxlength_alphanumeric(5)} //but here two logic are burried in one function
how to implement something like
normalize={maxlength(5) , alphanumeric}
We can implement this using closures, so we create a function that accept an array of normalization functions.
Note that this is different from validation because in validation all functions are not related if one of them fail it means validation failed.
While in normalization the value passed to each normalization function needs to be passed from the previous function that already did some normalization.
So we can do that using the
normalizeAll
function belowTo use
normalizeAll
now in your redux form you will do something like thisNote that this is assuming that all normalization functions are synchronous, i don't think that we usually have use cases where normalization function needs to be async, but the solution will still be the same but then we will use
callback
functions orpromise