feat: access of input value on template string for error messages #420
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Feat Error Template Message
Overview
The goal of this PR is to allow access of the input value on the error messages template strings via a
:inputValue
keyword.Use Case
A use case where user is making upload of an excel file with 100+ rows, and the validation of those fields throw an validation error just saying to the user that an error occurred is not very helpful.
It would be better to return the actual values(s) that are invalid so the user can find the values and perform the fixes.
Proposed implementation
Modify the
Messages._replacePlaceholders(rule, template, data)
to add therule.inputValue
to the data object. By doing this it will not collide with the existing implementation of:value
templater for the custom replacements.Object as input value
The default string representation of an
{}
is [object Object]. In order to make it more readable the behavior of the replacement will be to replace it for [Object] only.PS. It was also considered the option
{...}
. Open to feedback on this.Updated README.md
Updated the README to reflect the newly added feature.