ember-changeset-validations icon indicating copy to clipboard operation
ember-changeset-validations copied to clipboard

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

Open robinaugh opened this issue 1 year ago • 0 comments

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. 😄

robinaugh avatar Jul 14 '22 02:07 robinaugh