adopted-ember-addons / ember-changeset-validations

Validations for ember-changeset
http://bit.ly/ember-changeset-demo
Other
218 stars 100 forks source link

Update validateConfirmation to support confirmation against fields on ember-data objects #348

Open robinaugh opened 2 years ago

robinaugh commented 2 years ago

Changes proposed in this pull request

This addresses the use case I referred to in https://github.com/poteto/ember-changeset-validations/issues/137#issuecomment-1183397001, which is that when validateConfirmation's resulting function receives an ember-data object as its content, and the original field (say password) is unchanged from that ember-data object, the validating field (say passwordConfirmation) is considered invalid, no matter whether it matches the current content or not.

It looks like @brandynbennett took a stab at addressing this issue with #138 (later merged as #219 by @snewcomer), but that only works with POJOs whose top-level keys include the attributes we're targeting, which for ember-data objects are quite nested.

There may be a better way to grab all of an ember-data object's attributes than what I've got here, which admittedly uses their private API so I'm not thrilled about that, but it does get the job done. Open to suggestions if there's a better approach folks think we should take, or if the fact that we're seeing ember-data objects instead of POROS in a validator means we're just "doing it wrong" somewhere else in my team's code. 😄