final-form / react-final-form-html5-validation

A swap-in replacement for 🏁 React Final Form's <Field> component to provide HTML5 Validation
MIT License
57 stars 8 forks source link

expose errorKeys #11

Closed TrejGun closed 3 years ago

TrejGun commented 5 years ago

Are you submitting a bug report or a feature request?

feature request

What is the current behavior?

errorKeys are not exposed

What is the expected behavior?

errorKeys are exposed

curent code

var errorKeys = ['badInput', 'patternMismatch', 'rangeOverflow', 'rangeUnderflow', 'stepMismatch', 'tooLong', 'tooShort', 'typeMismatch', 'valueMissing'];
/// ...
export { Html5ValidationField as Field };

desireble code

var errorKeys = ['badInput', 'patternMismatch', 'rangeOverflow', 'rangeUnderflow', 'stepMismatch', 'tooLong', 'tooShort', 'typeMismatch', 'valueMissing'];
//...
export { Html5ValidationField as Field , errorKeys};

so i can consume it in my app like this

import {Field, errorKeys} from "react-final-form-html5-validation";

export default props => {
    const messages = {};

    errorKeys.forEach(key => {
      messages[key] = `My localized ${key}`;
    });

    return <Field {...props} {...messages} />;
}