Skip to content
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

SelectField in tag mode doesn't show error massage #985

Open
danyhiol opened this issue Jul 21, 2021 · 5 comments
Open

SelectField in tag mode doesn't show error massage #985

danyhiol opened this issue Jul 21, 2021 · 5 comments
Assignees
Labels
Area: Theme Affects some of the theme packages Theme: AntD Affects the uniforms-antd package Type: Bug Bug reports and their fixes
Milestone

Comments

@danyhiol
Copy link

This is a follow-up to this issue.
When using tag mode with SelectField with antd, the field is validated, but the validation message is not shown as an inline error below the field.
Please refer to the link for details.

"uniforms": "^3.5.1",
"uniforms-antd": "^3.5.1",
"uniforms-bridge-simple-schema-2": "^3.5.1",
"react": "^17.0.2",
"antd": "^4.16.8",
@radekmie radekmie self-assigned this Jul 30, 2021
@radekmie radekmie added the Type: Question Questions and other discussions label Jul 30, 2021
@radekmie
Copy link
Contributor

Hi @danyhiol, and sorry for the delay. Could you create a reproduction using our CodeSandbox template? It'd let us check it much faster.

@danyhiol
Copy link
Author

Here is a simple reproduction link.

@radekmie
Copy link
Contributor

Thanks! So, from what I can see, the problem is that these errors look like this:

[
  { "name": "activities.0", "value": "x", "type": "minString", "min": 10, "message": "Activities must be at least 10 characters" },
  { "name": "activities.1", "value": "xxxxxxxxxx", "type": "regEx", "regExp": /*...*/, "message": "Activities must be a valid email address" }
]

So the problem is that these are technically not errors of this component but its children. It's incorrect though, as it's responsible for these values. I'm not sure how to proceed on this one, as making these errors available to the parent field will break the rest, i.e., ListField.

As a workaround, you can create a custom SelectField that extracts these errors itself.

@radekmie radekmie added Type: Bug Bug reports and their fixes and removed Type: Question Questions and other discussions labels Jul 30, 2021
@radekmie radekmie added this to the v3.x milestone Jul 30, 2021
@radekmie
Copy link
Contributor

(We've had a team discussion about this issue, and here are the notes.)

  • We won't provide any further API for the childrenErrors. If needed, one can use bridge.getSubfields + bridge.getError/bridge.getErrorMessage.
  • We'll implement that for the built-in SelectFields (by rendering the first error).

@radekmie radekmie assigned Monteth and unassigned radekmie Jan 28, 2022
@radekmie
Copy link
Contributor

Here's a proof of concept of the error extraction:

const context = useField(props.name, {}, { absoluteName: true })[1];
const length = Array.isArray(props.value) ? props.value.length : 0;
const error = Array.from({ length }).reduce(
  (error, _, field) =>
    error ??
    context.schema.getError(joinName(props.name, field), context.error),
  props.error,
);

However, it requires an additional useField in the field component, that I don't really like. It is a start, though.

@radekmie radekmie changed the title antd tag mode not showing validation massage. SelectField in tag mode doesn't show error massage Jun 10, 2022
@radekmie radekmie added Area: Theme Affects some of the theme packages Theme: AntD Affects the uniforms-antd package labels Jun 10, 2022
@radekmie radekmie modified the milestones: v3.x, v4.0 Oct 7, 2022
@radekmie radekmie moved this to To do in Open Source Nov 18, 2022
@kestarumper kestarumper modified the milestones: v4.0, v4.x Apr 12, 2024
@piotrpospiech piotrpospiech moved this from To do to On Hold in Open Source Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Theme Affects some of the theme packages Theme: AntD Affects the uniforms-antd package Type: Bug Bug reports and their fixes
Projects
Status: On Hold
Development

No branches or pull requests

4 participants