formatResult
When applications consume validation results, they often need to augment or transform the validation results from the validators. Not all of those scenarios can be accomplished through Validator Result Props, and a different mechanism is needed. Strickland's formatResult
function can help. formatResult
wraps a supplied validator and uses a specified result formatter function to augment or transform the result from the validator.
Parameters
The formatResult
function accepts two parameters:
The result formatter function
The validator to wrap
The parameters are specified in this order to make it easy to use formatResult.bind()
with a result formatter function.
The result formatter function will be called with 2 parameters.
The result object from the validator, already normalized through Strickland's
validate
function.An object containing
{value, context}
wherevalue
is the value that was validated andcontext
is the validation context provided.
Usage
The following example shows how formatResult
can be used to augment the result of a very basic validator. The formatter uses the validated value
to generate a message
validation result prop.
Last updated