Meteor datepicker仅限月份和年份

时间:2016-02-18 23:45:31

标签: meteor meteor-autoform simple-schema

我目前正在使用aldeed:autoform-bs-datepickerrajit:bootstrap3-datepicker。我想将日期范围限制为年和月。我在帮助者中试过这个但是它没有用。有什么想法吗?

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

路径:Schema.js

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

1 个答案:

答案 0 :(得分:1)

试试这个:

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

您应该在呈现模板时初始化datepicker,而不是在帮助程序上。希望能帮助到你。另外,请确保日期选择器具有id="datepicker"

如果仍然无效,请按照以下方式修改您的架构并删除$("#datepicker")

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