az6bcn
az6bcn

Reputation: 339

AutoValues from Session.get()

I have a simple schema in other to use autoform in meteor. I am having problem with this field in my Schema. When I submit the form it does nothing. How can I set and insert the value of my id_master in the array with autoValues through the Session.get()?

master_id: {
    type: [String],
    label: "id_master",
    autoValue: function(){
    if( this.isInsert ) {
        var x =Session.get('id_master'); 
        console.log(x);//returns the value of id_master
       return [x]
        }
    }, 
    autoform:{
        type: "hidden"
    }

},

I'm using autoForm :

{{> quickForm collection="Hitos" id="insertHitosForm" type="insert" class="new-hito-form"}}

And I have allowed Inserting :

Hitos.allow({
        insert: function(userId, doc){
            //you are allowed to insert Hitos if userid exist
            return !!userId;

        }
});

Upvotes: 0

Views: 56

Answers (2)

blueren
blueren

Reputation: 2860

Looks like this was an issue earlier as well. Refer to this post

Try if something like this would work for you as well.

AutoForm.hooks({
     insertHitosForm:{
        before: {
          insert: function(doc) {
               doc.master_id = [Session.get('active_project')]
               return doc;
               }
        }
   }
});

Upvotes: 1

NFab
NFab

Reputation: 426

According to the documentation, you shouldn't need to, but have you tried using clean()?

AutoForm.hooks({
  insertHitosForm: {
    onSubmit: function (doc) {
      Hitos.clean(doc);
      console.log("Hitos doc with auto values", doc);
      this.done();
      return false;
    }
  }
});

Upvotes: 1

Related Questions