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
MyCollection.attachSchema(newSimpleSchema({qtys: {type: [newSimpleSchema({qty: {type: Number,autoform: {defaultValue: 1}}})],min: 1,autoValue: function(){if(this.isInsert&&!this.isSet){return[{qty: 1}];}},custom: function(){// Pay attention to the `length` and indexes of `this.value`console.log(this.value);}}}));
I noticed this when I was debugging a custom validation rule in the simple schema for the qtys field. Say I had three items, and I minused out the second item and hit save, it would break. I noticed that the this.value value in the custom validator showed an array with the remaining two items, but I noticed that their indexes were 0 and 2, and the length property showed 3, which was weird. So I had to _.compact(this.value), before I could do any custom validation or it would break on me.
And in order to fix this on the MongoDB operation side, I had to do a before.update collection hook where I would do:
MyCollection.before.update(function(userId,doc,fields,modifier,options){// Do some checks for my desired field.. blah blah.. modifier.$set.qtys=_.compact(modifier.$set.qtys);});
Because modifier.$set.qtys would be an array of three items, where the second item was a null value:
[{qty: 1},null,// here it is{qty: 3}]
The text was updated successfully, but these errors were encountered:
When submiting a form after removing exisiting items from array of Strings, the modifier gets array with null values in the place of the deleted strings, This fix correct it so the modifier gets array with only the remaining fields with the correct length.
Might solve the issues Meteor-Community-Packages#1263, Meteor-Community-Packages#1049, Meteor-Community-Packages#1004
Schema:
Form:
I noticed this when I was debugging a custom validation rule in the simple schema for the
qtys
field. Say I had three items, and I minused out the second item and hit save, it would break. I noticed that thethis.value
value in the custom validator showed an array with the remaining two items, but I noticed that their indexes were0
and2
, and thelength
property showed3
, which was weird. So I had to_.compact(this.value)
, before I could do any custom validation or it would break on me.And in order to fix this on the MongoDB operation side, I had to do a
before.update
collection hook where I would do:Because
modifier.$set.qtys
would be an array of three items, where the second item was anull
value:The text was updated successfully, but these errors were encountered: