Hello.
I add a custom option with extendOptions
this way:
SimpleSchema.extendOptions({
capilowerize: Match.Optional(Boolean)
});
Then I can write schema´s like this:
UsuarioSchema = new SimpleSchema({
nombre: {
type: String,
capilowerize: true
},
apellido1: {
type: String,
capilowerize: true
}
});
and add a global validator:
SimpleSchema.addValidator(function () {
if (this.definition.capilowerize && !_.isNull(this.value) && _.isString(this.value)) {
var string = this.value;
//Ex: FRED -> Fred
string = string.toLowerCase();
string = string.charAt(0).toUpperCase() + string.slice(1);
this.value = string;
console.log('[value]: "', this.value, '" on [key]: ', this.definition);
}
});
This work fine. Validator change this.value
but object inserted on collection still have original value. Say {nombre: ‘FRED’}.
What I do wrong??
Here is a test repo: https://github.com/bySabi/autoform-test checkout case1
branch.
Thanks.