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

INPUT - Setting value of auro-input to undefined does not reset error state #118

Closed
ethanwmiller opened this issue Nov 8, 2023 · 7 comments · May be fixed by #122
Closed

INPUT - Setting value of auro-input to undefined does not reset error state #118

ethanwmiller opened this issue Nov 8, 2023 · 7 comments · May be fixed by #122
Assignees

Comments

@ethanwmiller
Copy link

ethanwmiller commented Nov 8, 2023

Please verify the version of auro-input you have installed

2.15.1

Please describe the bug

  1. Create an error state on an auro-input component (for example, leaving a required field blank)
  2. Programmatically set the input's value to undefined
  3. The input's error state does not reset (pictured below)
Screen Shot 2023-11-08 at 11 21 13 AM

Reproducing the error on the docsite

This issue cannot be reproduced on the Auro docsite

Expected behavior

When the value of auro-input is set to undefined, it should completely reset the component, including error states.

What browsers are you seeing the problem on?

Chrome

Additional context

No response

@ethanwmiller ethanwmiller added not-reviewed Issue has not been reviewed by Auro team members Type: Bug Bug or Bug fixes labels Nov 8, 2023
@blackfalcon
Copy link
Member

@ethanwmiller thanks for your submission. Looking at this issue I can say a few things. The element's validation feature is triggered by blur events to re-evaluate. This is intentional to reduce the triggering of validation while someone is typing or otherwise.

If I am understanding the issue correctly, programmatically changing the value of the element is not triggering the blur event we are looking for.

Can you tell us more about the use case you have where there is an error on an element and you are programmatically removing the value of the input?

A proposed solution that may work is, if you are programmatically targeting the element to clear the content, you can also target the validity="valueMissing" in the DOM. Removing that attribute will remove the error UI you are looking for.

@ethanwmiller
Copy link
Author

@blackfalcon thanks for the response. Here is our use case in generic terms: when making a purchase, there is a "comments" input. By default, this input is not required. However, if a user adds a discount to their purchase, then the comments field is required. Finally, if the user removes the discount, then the comments field should be reset to its original state (blank and not required).

So the very specific case where this comes up is thus: they apply a discount, they focus into the comments field, they blur away from the comments field (triggering the "field is required" error) and then they remove the discount. The expected behavior is that the error state goes away. But it persists.

HOWEVER: your workaround works! Setting inputElement.validity = undefined in the same function that resets the value does reset the error state. We're good with that fix for now, but if you decide to update it to where setting the value also resets the validity then let me know. CC @jason-capsule42

@blackfalcon
Copy link
Member

@ethanwmiller I see your use case to be very interesting. What I can also suggest is that as you toggle the required state of the input, you can also add/remove the required attribute. Also you may want to look at the lesser known "Disable auto-validation" feature

https://auro.alaskaair.com/components/auro/input

Supporting your use case directly may be difficult to do as it requires some heavy state management and we tend not to do that, but using the API as described enables you to do that.

@Patrick-Daly-AA
Copy link

To be validated with Input's Beta Branch to see if this is still an issue.

@jordanjones243
Copy link
Contributor

jordanjones243 commented Sep 12, 2024

This "bug" is technically still valid as the experience can be replicated, but I am not sure if it should be classified as a bug. Currently, validation runs on change of input's value, validation is called manually or if certain attributes have changed.

In this case, setting the value of an input to undefined will not re-run validation because the value of a blank input is already undefined. I will talk with the Auro team about what we want the experience for this to be.

@jordanjones243 jordanjones243 removed the not-reviewed Issue has not been reviewed by Auro team members label Sep 12, 2024
@jordanjones243
Copy link
Contributor

After talking with the team, we have determined that this is a valid bug that will be fixed as a part of our "Booking Forms" milestone.

After further investigation, we have determined that the fix to this will be adding a function within auro-formvalidation to manually reset the validation of ANY form component, but will need to be tested locally to make sure the change will work with all of the form components.

@jason-capsule42 jason-capsule42 removed the Type: Bug Bug or Bug fixes label Oct 3, 2024
@jordanjones243 jordanjones243 self-assigned this Dec 16, 2024
@jordanjones243 jordanjones243 transferred this issue from AlaskaAirlines/auro-input Dec 16, 2024
@jordanjones243 jordanjones243 changed the title Setting value of auro-input to undefined does not reset error state INPUT - Setting value of auro-input to undefined does not reset error state Dec 16, 2024
@jordanjones243 jordanjones243 linked a pull request Dec 17, 2024 that will close this issue
@jordanjones243
Copy link
Contributor

The work to give the user the ability to reset the component to it's intial state will be addressed in this ticket:

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

Successfully merging a pull request may close this issue.

5 participants