cerebral-legacy / cerebral-module-forms

Form handling for Cerebral
http://cerebral-website.herokuapp.com/documentation/cerebral-module-forms
MIT License
12 stars 5 forks source link

validateForm issue #13

Closed haoguo closed 8 years ago

haoguo commented 8 years ago

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.

edgesoft commented 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?

edgesoft commented 8 years ago

@haoguo can you paste the index.js of the module and paste the state in that file? Or is it dynamically added?

edgesoft commented 8 years ago

@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.

haoguo commented 8 years ago

@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'.

edgesoft commented 8 years ago

@haoguo Ahh, yes you need to look at isTouched as well.

edgesoft commented 8 years ago

@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.

edgesoft commented 8 years ago

@haoguo I'm closing this. Open it again if you have problems after this discussion but I think this should work.