ember-changeset-validations
ember-changeset-validations copied to clipboard
Password confirmation validation is not working after validate()
Version 1.2.6
Test Case
https://ember-twiddle.com/a83d4a0647b7705a3759e9688006be2d?openFiles=templates.components.marketing-copy.hbs%2C
Steps to reproduce
Fill all the fields correctly and press "save" button 2 times
Expected Behavior
all validations should be correct
Actual Behavior
passwordConfirmation validation is failing and giving error: Password confirmation doesn't match password
This is happening for me as well. I noticed it after bumping to 1.2.6.
When I put a debugger in the confirmation validator the changes value is always empty.
I'm thinking it may be related to PR #143 in ember-changeset. It seems the confirmation validator was relying on the changes object to contain the model data, which is no longer being set in some cases
On these lines it looks like the changes are only set if the changeset is valid, however this is a circular dependency problem, because the confirmation validation relies on the changes so it will never be valid, which means the changes will never get set and so on...
Another problem is that changes does not include the initial values of the model nor does it include invalid values. A validator like confirmation that depends on the state of other fields really needs to be able to access the current state of the data including invalid, valid, and initial values. I don't think there is a mechanism like this in the addon.
Today I also encountered the circular dependency issue on confirmation, as described clearly by @brandynbennett. A confirmation field should not be marked as invalid if it matches the field it's confirming, even if the field it's matching is itself invalid. The current API design for validators only allows insight into valid changes that have been made, so there is currently no way to make this work as desired.
Any news concerning this bug? Here is the case: On a subscription form, when clicking signup, the changeset is validated then saved. But if server returns an error (like duplicate email), then changing only the email doesn't validate the changeset as the confirmation fails... even when changing password and confirmation...
Any workaround to make it work?
@fiftoine Hi, do you mean you want to trigger the validation when the api called is failed? like email is not available etc?
@emparker , no, validation is triggered on form submition, but when the form IS valid and sent to server but server responds with an error, the changeset stays bound to the form and the problem with the confirmation occurs...
Have the same error. Any workarounds on this?
Also having problems with this issue in v2.1.0.
This appears to still be an issue, even after #138 and #219, because the content object is an ember-data model instance, rather than a plain object, so this merging of the two objects does not put the keys on the same level, i.e. in this screenshot where the existing content object has a routingNumber to match against routingNumberConfirmation, but it's not a top-level key on the model object so it fails validation:
Is there a chance my project is just wiring things up wrong somewhere (resulting in the validator receiving an entire model instance rather than just a POJO of the attributes), or would it make sense to PR a change to the validator here?
cc @brandynbennett @snewcomer
EDIT - I went ahead and opened https://github.com/poteto/ember-changeset-validations/pull/348 with the solution we're using on my team to work around this, in case there's appetite to merge that into the project. Thanks!