-
-
Notifications
You must be signed in to change notification settings - Fork 245
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
Pass in an existing document to update, passing model breaks validatation #3
Comments
Actually it is validating new model. Could you share a not working example? |
I'll close it for now. If problem persist, please let me know. |
I am also experiencing this issue, when I use |
Could you share some more code, @todda00? |
I was able to determine the issue is with a document which has collection helpers (https://github.com/dburles/meteor-collection-helpers) on it, providing prototype functions on the object. The following is my user schema and collection helpers:
I am using Matra, here is my container:
The Register component has some common elements, but nothing to do with this issue, so I will just show you the component which shows the form (In reality I am using a mix of custom and AutoField and other types, but using the autogenerated AutoForm has the same issue, so I will simplify my example):
This all works when I remove the collection helpers. Here is the user object with collection helpers: |
HA! yes indeed - I also use |
It's interesting, but it seems that's a problem of SimpleSchema itself. I'll try to find out, what's going on. |
Unfortunately (is it?) it's a SimpleSchema problem. It simply does nothing with non-plain objects. There's also an issue for that. Unluckily, it's almost one year old. |
I was able to get this to work if I convert my object to a basic object using this (uses lodash's forOwn):
Then using basicObj as the model to validate, it works. Would this be a bad idea to incorporate into this project, stripping out any model's inherited properties, since SimpleSchema will ignore the whole object otherwise? |
You can simplify it - I think it's not necessary because it will cause additional overhead if you are not using prototype-based documents. |
I certainly think this is a gotcha worth a bit of code in package, to avoid users having to run into issues trying to use the package... especially since, inside the package, it is basically only required when ingesting the initial model |
getValidator (options = {clean: true}) {
const validator = this.schema.validator(options);
- return model => validator(cloneDeep(model));
+ return model => validator(cloneDeep({...model}));
} This change in |
How do you pass in an existing document to update?
When I try to pass it in as a
model
- values update in the form but validation no longer throws errors (I assume because it's not validating the new data??)The text was updated successfully, but these errors were encountered: