tmpfs / async-validate

Asynchronous type validation for node and the browser
Other
314 stars 45 forks source link

empty string should be raised when rules include `required` #58

Closed lcygithub closed 8 years ago

lcygithub commented 8 years ago

empty string should be raised when rules include required,in utils.js ,function required should be

if (!this.isRoot() && this.rule.required && (!this.source.hasOwnProperty(this.field) || this.value === undefined || this.value === null || this.value === ""))

notice the this.value === ""

tmpfs commented 8 years ago

Not so by design, the required field tests whether an expected property is specified. For strings that you do not want to be empty (or consist solely of whitespace) use the whitespace property.

See: https://github.com/tmpfs/async-validate/blob/6fb83e05400d9a112e5164ae73ca02829ff516b1/plugin/string.js#L22-L29