vendredi 27 novembre 2015

Meteor: Insert Checkbox (as Boolean) into Sub-Schema (aldeed2)

I'm trying to insert the checkbox value (as boolean) into a subschema of my collection. Not clear on 1) how to pass the checkbox value (can do it for normal input field) and 2) how to insert into subschema. I am using collection2 and handlebars.

1-This is what I have in the HTML form that needs to be submitted:

`<div class="checkbox">
<label><input type="checkbox" id="byow" checked="{{isChecked}}" value="">Bring Your Own Wine</label></div>` 

2-This is what I have in my helper (in controller) to get the value of the form and the checkbox value, submit it and call the method that inserts it into the collection:

`BackendController.events({

    //Add Venue - Add New Venue Submit Form Helper
     'submit #add-venue-form' : function(event) {

        event.preventDefault();

        var venueName = event.target.venueName.value;
        var byow = event.target.byow.checked;

        var params = {
            venueName: venueName,
            byow: byow
        }

        //Insert Venue
        Meteor.call('addVenue', params);
        toastr.success('VenueAdded');
        Router.go('/admin/manage-venues')
    }

3-This is my method that is called to insert into my Venues collection (first part) and the structure of my collection and sub-collection:

`Meteor.methods({
  'addVenue': function (params) {
    Venues.insert(params);
  }

// MAIN SCHEMA for the Venues colleciton. 
Schema.Venues = new SimpleSchema({
    venueName: {
        type: String,
        label: "Venue Name",
        max: 200,
        optional: false
    },
        //Attach schema for venue attributes (cuisine type, amenities, etc)
    venueAttributes: {
        type: Schema.VenueAttributes,
        optional: true
    }
});

//schema for venue attributes. Attached to main schema
Schema.VenueAttributes = new SimpleSchema({
    byow: {
        type: Boolean,
        optional: true
    }
});

Would really appreciate any help - I've managed to get the venueName to be passed successfully (so all my permissions/pub/sub is correct) but stuck at checkbox and subcollection.

Thanks! Dan.




Aucun commentaire:

Enregistrer un commentaire