Closed haoguo closed 8 years ago
@haoguo Can you send the app state of the form so that maybe we can reproduce the error. If you have cerebral debugger you will be able to paste it from there. Do you have a validation message on index 0?
@haoguo can you paste the index.js of the module and paste the state in that file? Or is it dynamically added?
@haoguo If 0 is passed then it's the first validator that is set up in the form
Form({
email: {
value: '',
validations: ['isEmail'],
errorMessages: ['Please fill in a correct email']
}
})
So the first validation corresponds to the first errorMessage.
@edgesoft I am sorry for not giving you a prompt reply.
I use this as below.
fieldDetails: { value: '', validations: ['maxLength:20'], errorMessages: ['error_sample'], isRequired: true, }
When I use formValidated to valid this and the value is empty at the same time. The errorMessage of this field is set to 'error_sample'.
@haoguo Ahh, yes you need to look at isTouched as well.
@haoguo
renderErrorMessage(){
const {field} = this.props
if( field.errorMessage && field.isTouched ){
// show.
}
}
if you use formValidated and the value is '' then errorMessage should be 'error-sample' this is correct behaviour.
@haoguo I'm closing this. Open it again if you have problems after this discussion but I think this should work.
in actions/validateForm line 32 36
var isValid = result.isValid && !isRequired(field); errorMessage: isValid ? null : field.errorMessages[result.failedRuleIndex],
the result.failedRuleIndex is 0 if it pass. we don't know which the error is.