Skip to content

[Error] Add error messages #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
AleksandarDev opened this issue Mar 21, 2022 · 1 comment
Open

[Error] Add error messages #30

AleksandarDev opened this issue Mar 21, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@AleksandarDev
Copy link
Member

AleksandarDev commented Mar 21, 2022

Current usage:

<MyInput
    error={formData.name.error}
    helperText={formData.name.error ? 'Field \'Name\' is required.' : ''}
    ... />

Which is fine when we have one validation on field. But when there is more than one validator, it would be nice to show user which one is failing eg. have validation message/text.


Proposed new format:

t is translator function here

<MyInput
    error={formData.name.error}
    helperText={formData.name.errorMessages.map(t).join('. ')}
    ... />
{value: "", error: false, errorMessages: ["required"], onChange: ƒ, onBlur: ƒ, validate: ƒ, reset: f}

Each validator would correspond to different message in "keyed" format so it can be passed forward to localization functions.

Validation function could return the errorMessages item as string. Validation needs to be changed. When returned value is typeof string there is error (like current false value), and when there is no error typeof boolean && === true is expected. For validators that are not updated (for backward compatibility) default error message would be used when they return false.

@AleksandarDev AleksandarDev added the enhancement New feature or request label Mar 21, 2022
@radovix
Copy link
Member

radovix commented Mar 21, 2022

@AleksandarDev thanks for that suggestion. I will think and see what can be done about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants