SimpleSchema: Gender is required


#1

Hey guys,
I’m using the SimpleSchema package, combined with Autoform. Now I try to add a user with the following required fields:

  • email
  • username
  • password

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?


#2

Did you have gender has required before?

try add to gender optional:true


#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?


#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).


#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.