Skip to content

Add #removeError and #removeErrors to BufferedChangeset #189

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

Merged
merged 4 commits into from
Mar 20, 2025

Conversation

jkeen
Copy link
Contributor

@jkeen jkeen commented May 17, 2023

I'm using ember-changeset with ember-changeset-validations with some validations where the presence requirement of one field is dependent on the value of another. If the dependent field ends up with an error and then the field it depends on changes, the error should really be cleared. But it didn't seem like there was a clean way to do that without actually rolling back the property. This seems to have come up a number of times in issues and PRs.

This seems to be something that works in the newer validated-changeset 4.x-5.x experiment, but is not something available in the classic BufferedChangeset.

adopted-ember-addons/ember-changeset#361
adopted-ember-addons/ember-changeset#282

There were some workarounds in the above threads, like effectively "clearing" an error by changeset.addError('email', null), but in my testing it still left the changeset with an isValid = false state.

This PR adds removeError and removeErrors to BufferedChangeset, mirroring the behavior in the newer ValidatedChangeset, and opening the door for an ember-changeset PR making this interface public.

This also should address #170

@RuslanZavacky
Copy link

@jkeen thank you for this PR! I hope it can be merged :) as it is very useful

@jkeen
Copy link
Contributor Author

jkeen commented Mar 19, 2025

@mansona Any chance this could be considered for merging?

I just updated the linked PR on ember-changeset, but it depends on this one getting merged first. I still think this would be a good addition to the code base, and one I have been using in production via a private fork for almost two years now. Would be great to sync back up with the released version :)

@jkeen
Copy link
Contributor Author

jkeen commented Mar 20, 2025

#200

^ This PR should get tests passing on this branch again

Copy link
Collaborator

@knownasilya knownasilya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks mostly there, just a couple items

@knownasilya knownasilya added the enhancement New feature or request label Mar 20, 2025
@knownasilya knownasilya merged commit f652133 into adopted-ember-addons:main Mar 20, 2025
4 checks passed
@github-actions github-actions bot mentioned this pull request Mar 20, 2025
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

Successfully merging this pull request may close these issues.

3 participants