Simpanoz
Simpanoz

Reputation: 2859

meteor autoform: how to ignore simple schema key during insert or update

I have following simple schema keys:

isParent: {
    type: String
   ,optional: true        
   ,custom: function(){
        if(  !this.isSet ){
            console.log('IsParent value: ',this.field.value);
            return 'required';
        }
   }
},
parentId: {
    type: Number
   ,optional: true
   ,custom: function(){

        if( (this.field('isParent').value === 'false') && !this.isSet ){

            console.log(this.field('isParent').value);
            console.log('ParentId value: ', this.value);
            return 'required';
        }            
    }

I don't want to insert/update 'isParent' key in db. I only want to use it as trigger point to enable/disable the 'parentId' key in html form and in schema.

If I don't use 'isParent' key in insert process, then meteor error is generated.

Can some one guide me how to ignore insertion or updation of 'isParent' key during validation upon insert or update.

Upvotes: 0

Views: 415

Answers (1)

Rafael Quintanilha
Rafael Quintanilha

Reputation: 1432

Not sure if I got what you're asking, but what's the point in storing the value of this isParent boolean? Simply makes it a JavaScript trigger but don't save it into dB. Then you can just check the parentId to know if someone's has or not parents.

Being more straightforward, you can set up a checkbox (for example) that is not attached to the schema (use autoform instead of quickform) and surround the parentId part of the form by a if clause reactively triggered by the event of clicking or not the checkbox.

Upvotes: 1

Related Questions