LT-67: Creating default custom validatior for empty strings

This commit is contained in:
Bruno Alves de Faria committed 2016-08-31 09:51:28 -03:00
1 parent e5eb98cbc0
commit a057243745
4 files changed
+51 -5

No files matched your search

+23 -1
View File
@@ -1,5 +1,27 @@
import { SimpleSchema } from 'meteor/aldeed:simple-schema';
/*
Extend the available options on schema definitions:
* valuesLabels: Used in conjunction with allowedValues to define the text
label for each value (used on forms)
* textOptional: Used to allow empty strings
*/
SimpleSchema.extendOptions({
valuesLabels: Match.Optional([String])
valuesLabels: Match.Optional([String]),
textOptional: Match.Optional(Boolean)
});
// Add default required validation for empty strings which can be bypassed
// using textOptional=true definition
SimpleSchema.addValidator(function() {
if (
this.definition.optional !== true &&
this.definition.textOptional !== true &&
this.value === ''
) {
return 'required';
}
});