Skip to content

[Error] Add error messages #30

@AleksandarDev

Description

@AleksandarDev

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.errorKeys.map(t).join('. ')}
    ... />
{value: "", error: false, errorKeys: ["required"], errorMessages: ["This field can not be empty."], onChange: ƒ, onBlur: ƒ, validate: ƒ, reset: f}

Each validator would correspond to different message in "keyed" and "user-friendly" formats so it can be passed forward to localization functions or displayed directly.

Validation function could return the errorKeys and 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.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions