Meteor datepicker month and year only

370 Views Asked by At

I'm currently using aldeed:autoform-bs-datepicker and rajit:bootstrap3-datepicker. I would like to limit the date range to year and month. I've tried this in the helpers but it doesn't work. Any thoughts?

Template.user.helpers({
    datePicker: function() {
            $("#datepicker").datepicker( {
            format: "mm/yyyy",
            startView: "months", 
            minViewMode: "months"
        });
    }
});

Path: Schema.js

Schema.Date = new SimpleSchema({
    startDate: {
        type: Date,  
        optional: true,
        autoform: {
            type: "bootstrap-datepicker",
            "data-date-autoclose": "true"
        }    
    }
});
1

There are 1 best solutions below

4
On BEST ANSWER

Try this:

Template.user.onRendered(function() {
  $("#datepicker").datepicker( {
    format: "mm/yyyy",
    startView: "months",
    minViewMode: "months"
  });
});

You should initialize the datepicker when the template is rendered and not on the helper. Hope it helps. Also, make sure the datepicker has id="datepicker"

If still doesn't work, modify your schema as follows and get rid of $("#datepicker"):

Schema.Date = new SimpleSchema({
  startDate: {
    type: Date,
    optional: true,
    autoform: {
      type: "bootstrap-datepicker",
      datePickerOptions: {
        format: "mm/yyyy",
        startView: "months",
        minViewMode: "months"
      }
    }
  }
});