0

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"
        }    
    }
});
Stephen Woods
  • 4,049
  • 1
  • 16
  • 27
bp123
  • 3,217
  • 8
  • 35
  • 74
  • Thanks for the suggestion. I tired that however it didn't work. Do you need more information? – bp123 Feb 19 '16 at 00:22

1 Answers1

1

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"
      }
    }
  }
});
lucascurti
  • 86
  • 1
  • 8
  • That didn't seem to work either. I've attached the schema (see above). Should #datepicker be #startDate or something else? – bp123 Feb 19 '16 at 00:30
  • Got it. Let me create a Meteorpad for you and I'll edit my answer with suggestions. – lucascurti Feb 19 '16 at 01:00
  • Seems Meteorpad.com is down. Let me know if setting the options on the Schema works for you. – lucascurti Feb 19 '16 at 01:05
  • Fantastic! If i drop the template.user.Onrendered and just use your schema solution it works a treat. Thanks @lucatros ! – bp123 Feb 19 '16 at 01:27