Meteor-Community-Packages / meteor-simple-schema

Meteor integration package for simpl-schema
https://github.com/Meteor-Community-Packages/meteor-simple-schema
MIT License
920 stars 162 forks source link

How does this.isSet in custom validation behave? #704

Closed luixal closed 6 years ago

luixal commented 7 years ago

Hi, I'm facing something kind of weird...

I have this definition for a field inside a schema:

pin: {
    type: Number,
    label: function() { return I18N.translate('employee_pin'); },
    optional: true,
    custom: function() {

      if (Meteor.isClient && this.isSet) {
        console.log(this); // --> this gets fired ALWAYS!!!
        if ( (this.value <= 0) || (this.value >= 100000000) ) {
          Employees.simpleSchema().namedContext("modalForm").addInvalidKeys([{name: "pin", type: "outOfRange"}]);
          return 'outOfRange';
        }
        Meteor.call(
          'getEmployeeByPIN', Meteor.user().currentProjectId, this.value,
          function(error, result) {
            if (result) {
              Employees.simpleSchema().namedContext("modalForm").addInvalidKeys([{name: "pin", type: "notUnique"}]);
              return 'notUnique';
            }
          }
        );
      }
    }
  },

that console logs shows this object:

...
docId: "6QQTMm7CrQx7MdeAM"
genericKey: "pin"
isFromTrustedCode: false
isInsert: false
isLocalCollection: false
isSet: true
isUpdate: true
isUpsert: false
key: "pin"
operator: "$unset"
userId: "4dy58r789bBqYKky6"
value: ""

this happens when updating a doc using AutoForm's quickform.

Any idea why isSet is set to true if field is not being filled in? It's madness.

aldeed commented 6 years ago

The Meteor SimpleSchema package is no longer maintained other than critical fixes to keep it running with each latest Meteor release. Closing non-critical issues in this repo. Anyone who cares about this may do one or more of the following: