react-validation icon indicating copy to clipboard operation
react-validation copied to clipboard

Creating a form target class for hints?

Open carliecope opened this issue 8 years ago • 5 comments

I have a custom styled form and upon validation I'd like to add all of the returned span tags from the hint functions to a single 'error' div for the form, rather than having them display per input. Is this currently possible?

carliecope avatar Nov 04 '16 19:11 carliecope

Hey @carliecope ,

I assume you also need some mapping to the validation Components. So for instance you'll show hints like: Input 'inputName' is required. Input 'otherInputName' should be alpha.

Am I correct?

Lesha-spr avatar Nov 06 '16 14:11 Lesha-spr

@Lesha-spr

Yes, mapping to the validation Components and their corresponding hints would be helpful

carliecope avatar Nov 07 '16 15:11 carliecope

👍

pr1ntr avatar Nov 16 '16 08:11 pr1ntr

Hello, is there any progress on this. Do you need any help?

ajorquera avatar Mar 16 '17 11:03 ajorquera

Hey, I have a same kind of issue. I´dd like to have the name of the current prop in the hint of the error. But I only get the components. I want to make different hint messages for each input field, but the validating will remain the same. So I´dd rather not have a whole bunch of validation names. I like to do something like this:

Object.assign(Validation.rules, {
    required: {
        rule: (value) => {
          if (value) {
            return !!value.toString().trim();
          }
          return false;
        },
        hint: (value, components, current) => {
          const name = current.props.name;
          if (name == 'gender') {
            return <span
              className='form-error is-visible'>{gettext('Please choose a title')}</span>;
          } else {
            return <span
              className='form-error is-visible'>{gettext('Required')}</span>;
          }
        }
    },

DidiWillems avatar Aug 17 '17 09:08 DidiWillems