Closed th0r closed 9 years ago
Hi, the current signature is
validate(value, type, [path]) -> ValidationResult
What about replacing the path
argument with a context
argument?
validate(value, type, [context]) -> ValidationResult
value
the value to validatetype
a type defined with the tcomb librarycontext
(optional) passed in to getValidationErrorMessage
(useful for i18n)where getValidationErrorMessage
will have the following signature:
getValidationErrorMessage(value, path, context)
Note.
context
can be an array (as path prefix) for backward compatibility (deprecated)path
key that will be used as path prefix.@gcanti The only concern I have is that path
is an option, while context
values are not.
So, maybe something like this?
validate(value, type, [options]) -> ValidationResult
options
(optional) is an object with the following keys:
path
- path prefix for validationcontext
- passed to getValidationErrorMessage
(useful for i18n)options
can be an array (as path
prefix) for backward compatibility
:+1:
Just published v2.2.0 https://github.com/gcanti/tcomb-validation/releases/tag/v2.2.0 Let me know if everything's ok Giulio
@gcanti Incredible speed, man! Thanks!
@gcanti It would be great to add context support to tcomb-form
.
Hi and thanks for the great lib!
I have one question though: what is the proper way to return localized error messages from
getValidationErrorMessage
function?The problem is I have to pass user's locale into this function somehow in order to return proper error message and the only solution I found now is to construct one struct per locale (but I don't like it):
The other solution could be is to pass an external
options
(orcontext
) argument tovalidate()
. Then this example would look like this:What do you think about it?