Meteor-Community-Packages / meteor-simple-schema

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

Make a field conditionally required bug #724

Closed vfonic closed 6 years ago

vfonic commented 6 years ago

I haven't tested this, but I believe there could be a bug in the code example in Readme documentation: https://github.com/aldeed/meteor-simple-schema#make-a-field-conditionally-required

Specifically this line: if (this.operator === "$set" && this.value === null || this.value === "") return "required";

I assume the correct line of code would be: if (this.operator === "$set" && (this.value === null || this.value === "")) return "required";

The issue is that && operator executes before || operator so this.value === "" doesn't depend on this.operator === "$set". If this is intended, perhaps it should be elaborated or surrounded by parenthesis (even though you might argue that those parenthesis are redundant).

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence

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: