You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using ember-changeset v4.1.2 (validated-changeset v1.3.4) and have an ES6 class with a tracked property whose value is either null or a moment instance. If that property on an instance of the class is set to a moment instance and I create a Changeset around the object, when I call the object's .validate() method the value passed into the validator as the newValue is a plain object with the properties of the moment instance copied onto it. The validator checks the value's .isValid() method, which is part of the moment object but is not present on the newValue received by the validator. The issue seems to be caused by the unwrap method creating a plain object instead of returning the original class.
Repro:
importmomentfrom'moment';classFormData{date=moment();}constformData=newFormData();constvalidator=({ newValue })=>{returnmoment.isMoment(newValue)&&newValue.isValid();};constchangeset=Changeset(formData,validator);changeset.validate('date');// results in `TypeError: newValue.isValid is not a function` being thrown.
Perhaps I'm thinking about this in the wrong way, but it seems reasonable to expect that the newValue provided to a validator has the same signature as the underlying value, otherwise validator functions lose access to methods that were present on the original data type that are often useful as part of the validation routine.
The text was updated successfully, but these errors were encountered:
I'm using
ember-changeset
v4.1.2 (validated-changeset
v1.3.4) and have an ES6 class with a tracked property whose value is eithernull
or amoment
instance. If that property on an instance of the class is set to amoment
instance and I create a Changeset around the object, when I call the object's.validate()
method the value passed into the validator as thenewValue
is a plain object with the properties of themoment
instance copied onto it. The validator checks the value's.isValid()
method, which is part of themoment
object but is not present on thenewValue
received by the validator. The issue seems to be caused by theunwrap
method creating a plain object instead of returning the original class.Repro:
Perhaps I'm thinking about this in the wrong way, but it seems reasonable to expect that the
newValue
provided to a validator has the same signature as the underlying value, otherwise validator functions lose access to methods that were present on the original data type that are often useful as part of the validation routine.The text was updated successfully, but these errors were encountered: