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

errorMessage for required field. #5

Closed kgdev closed 8 years ago

kgdev commented 8 years ago

Right now there is no way to provide an error message for a required field if it has no valid.

abalmos commented 8 years ago

Could pull a "required" error message from errorMessages here:

https://github.com/cerebral/cerebral-module-forms/blob/misc-features/actions/validateRequired.js#L11

and here

https://github.com/cerebral/cerebral-module-forms/blob/misc-features/helpers/configureField.js#L26

edgesoft commented 8 years ago

@kgdev You could just use minLength:1

kgdev commented 8 years ago

required != minLength:1

If the field is optional and it's empty, it will by pass all the other rules.

christianalfoni commented 8 years ago

Yeah, I agree with @abalmos on adding a field for the required error message. Required and validation are two different things really. As required means "no value" and validations means "Value, but invalid value".

So a requiredMessage f.ex.

edgesoft commented 8 years ago

Sound good!

edgesoft commented 8 years ago

@christianalfoni @Guria Then maybe we can close this issue?

Form({
  name: {
     isRequired: true,
     value: ''
     requiredMessage: 'Please Fill in the data'
  }
})

Later in Component

renderRequiredMessage(){
  const {form} = this.props;
  // render requiredMessage based on conditions
}
christianalfoni commented 8 years ago

Yeah, this sounds like a good thing, you want to implement @edgesoft ? :)

edgesoft commented 8 years ago

@christianalfoni Do we really need to implement this? When constructing the form just pass requiredMessage as an option, and in the view layer check isTouched?

christianalfoni commented 8 years ago

Ah, yeah, sorry... good point :)

edgesoft commented 8 years ago

@kgdev I'm closing this. Reopen it again if this approach doesn't work for you.