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

bug(Field.PostalCodeAndCity): postalcode field doesn't display a red error border when error #2968

Closed
langz opened this issue Dec 5, 2023 · 4 comments · Fixed by #3225
Closed
Assignees
Labels
bug Something isn't working
Milestone

Comments

@langz
Copy link
Contributor

langz commented Dec 5, 2023

🐛 Bug Report

PostalCodeAndCity's postalcode field doesn't display a red error border when error

To Reproduce

Steps to reproduce the behavior:

https://codesandbox.io/p/sandbox/empty-firefly-7ppx4n?file=%2Fsrc%2FApp.tsx

Type in "1" in the postal code field, and tab to the next field.
You'll be presented with an error message, but no red/error border around the postal code field, to indicate which field that causes the error. Looking like:
image

Expected behavior

Reason for expecting a red/error border around the field that has the error is because all/most other <Field.X />-components behaves this way, having an error/red border, like:

Screenshot 2023-12-05 at 12 59 08 Screenshot 2023-12-05 at 12 59 01 Screenshot 2023-12-05 at 12 59 16
@langz langz added this to the Forms Release milestone Dec 6, 2023
@langz langz changed the title PostalCodeAndCity postalcode field doesn't display a red error border when error bug(Field.PostalCodeAndCity): postalcode field doesn't display a red error border when error Dec 6, 2023
@langz langz added the bug Something isn't working label Dec 6, 2023
@joakbjerk
Copy link
Contributor

joakbjerk commented Dec 6, 2023

The culprit seems to be a check, inside the useDataValue hook, that sees if the component/hook is used inside a FieldBlock component, so any component inside a field block will not receive the red border-color on error. This affects the PhoneNumber component too.

Screenshot 2023-12-06 at 12 50 59

Not sure about what the best approach to fix this would be 🙏

@snorrekim
Copy link
Contributor

snorrekim commented Jan 9, 2024

This has since been solved for some of the Field.Date and Field.String (https://github.com/dnbexperience/eufemia/pull/3081/files#diff-82c0dcb982ee31d1da123e9178b9a9b8a595e5278293b79374ebba6e3a35cbdb). But we will have to do so for all the Field types if we want to solve this issue for good.

And hasError is a bit of an odd name, it basically means, "this field has an error but you don't have an error message to show, so only add the red border". I think a better solution would be to either:

  • Rename the error prop to errorMessage, and make hasError the main property used for deciding visuals.
  • Send in an false as error to activate the styling, but not show a message
  • Send in the error, but change hasError to isInFieldBlock and let the Field handle the visuals based on that info

@snorrekim snorrekim self-assigned this Jan 9, 2024
@snorrekim
Copy link
Contributor

I think I'll go for "Send in an false as error to activate the styling, but not show a message". That solves it for all Fields without needing to make any changes to their code.

@snorrekim
Copy link
Contributor

It works, but technically the error prop is not supposed typed as a boolean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
3 participants