XTA
September 20, 2015, 3:01pm
1
Hey guys,
I’m using the SimpleSchema package, combined with Autoform. Now I try to add a user with the following required fields:
Okay, also I’ve some optional values in my Schema:
search: {
type: Object,
optional: true
},
"search.genders": {
type: [String],
allowedValues: ['male', 'female'],
autoform: {
options: function () {
return [{label: "Männer", value: "male"},{label: "Frauen", value: "female"} ];
}
}
}
If I try to add a new user, I get the error: “Genders is required”. A few days ago it worked fine. What I’m doing wrong?
1 Like
narven
September 20, 2015, 3:46pm
2
Did you have gender has required before?
try add to gender optional:true
narven
September 20, 2015, 3:48pm
3
Also if your specifying allowedValues… it must have one, try add a defaultValue:"female"
if you want or… has i said before, optional:true
Also why are you saying type: [String], ?? is it really an array of strings? or just a string?
XTA
September 20, 2015, 3:51pm
4
Hi,
if I add optional:true
to it, it works - but if I look into the documentation, it should be okay to add optional:true
to the parent (also it worked a few days ago without problems). The funny thing is, that the following is also not working anymore:
“search.genders”: { optional: function() {
console.log(this.isInsert);
if(this.isInsert}
{ return true; } else { return false; } }
The prop “isInsert” is now undefined.
–
Yeah, it is an array, because the user can search for multiple genders (male and female).
XTA
September 21, 2015, 10:08am
5
To solve it: I found the problem. I’ve a field in my “search object”, that has an autoValue
, f.e.
"search.status":
{
type:String,
autoValue: function() { if(this.isInsert) {return 'hidden'; }}
}
I need that field to give a user a “start value” after registratiion. SimpleSchema then requires automatically all others search.x
fields, if they are not explicit optional.