mercredi 31 août 2016

Insert into collection if checkbox input is checked

What I'm trying to do: I'm using a checkbox in a form that when checked and submitted using a button, it will create a new item in a collection.

Checkbox > Checked > Form Submit > Create new item in a collection.

Checkbox > Unchecked > Form Submit > Do not create the collection.

I have a collection Schema with the following:

value: {
    Type: Boolean, 
    ...
}

With a default of false. This is fine.

What I have tried I have tried two different ways to pass this through to Meteor server side to insert the new collection:

  • On change of checkbox, update DB value and on submit, check the value in db, if false, don't make collection, if true, make it.

  • On submission of form, check if checkbox is checked or unchecked and create the new collection based on this.

Neither worked as I don't know how to pass the content from the HTML to the js file within Meteor. I know how to do this via JavaScript etc.

I'm using a simple if(value) { } but it seems this is only checking if the input exists and is always return true.

I've tried document.getelementbyID, this returns undefined on document. I've tried using it as an event, this returns that events is undefined.

My question:

How do I pass a checked/unchecked value into the Meteor Javascript?




Aucun commentaire:

Enregistrer un commentaire