Closed skrobek closed 8 years ago
Hi,
So the validation works fine
No, what you are reporting is the message caused by a failing assert, a correct refinement definition would be:
// invalid type definition
const customValidation = t.refinement(t.String, customRules) // customRules is a type, not a predicate
// ok
const customValidation = t.refinement(t.String, customRules.is)
Still you can't get the correct error messages because intersections are not supported by tcomb-form
at the moment.
@gcanti Ok I got it. Is there any other way to add few validators to one field? Maybe union?
Best bet atm is to define a single refinement type:
const max = (s) => s.length < 10
const min = (s) => s.length > 3
const MinMax = t.refinement(t.String, (s) => min(s) && max(s), 'MinMax')
MinMax.getValidationErrorMessage = (value) => {
if (!value) {
return 'Required'
}
if (!min(value)) {
return 'Value can\'t be shorter than 3.'
}
if (!max(value)) {
return 'Value can\'t be longer than 10.'
}
}
@gcanti Thank you for help.
Hi,
Im trying to build a validation based on a config. Let's say that we have an input which can accept string (min length 3, max length 10), based on this example: https://github.com/gcanti/tcomb-validation#intersections
First define validators subtypes:
Then fields configuration types:
What I have noticed, that in the console I can see validation messages:
So the validation works fine. The problem is that I can't see any error in the input form. There is no calss "error" and errorMessage it's not visible. I know that I can use one validator for this example but It's only for showcase purposes. Let's say that we want to mix very different predicates.
Can you please check this case or point me where I made a mistake?