[英]How to call “onSelect” function for bootstrap3-datetimepicker? jQuery
I am using Rails 4 and I have the gem bootstrap3-datetimepicker-rails
installed. 我正在使用Rails 4,并且安装了
gem bootstrap3-datetimepicker-rails
。
It is working fine, but I want to be able to do an onSelect
call like I can with the normal bootstrap-datepicker. 它工作正常,但我希望能够像使用常规bootstrap-datepicker一样进行
onSelect
调用。
I want to be able to do something like this: 我希望能够做这样的事情:
$("#start").datetimepicker({
minDate: new Date()
}).on("change", function(selectedDate) {
$("#end").datetimepicker({ minDate: selectedDate });
});
$("#end").datetimepicker();
but the documentation is very vague and doesn't seem to include anything on this concept. 但是文档非常模糊,似乎没有包含有关此概念的任何内容。 I am still pretty surprised that this feature of validating start and end dates is not a native option in any date or time picker.
我仍然很惊讶,验证日期和结束日期的功能不是任何日期或时间选择器中的本机选项。
How would I realize this? 我将如何实现?
Note : I am using bootstrap3-date time picker, not the regular bootstrap-datepicker and not jquery-datetimepicker. 注意 :我使用的是bootstrap3-date 时间选择器,而不是常规的bootstrap-datepicker,而不是jquery-datetimepicker。
Side Note: I've always felt that the world's most ideal automatic datepicker validation would look something like this: 旁注:我一直觉得世界上最理想的自动日期选择器验证看起来像这样:
$("#start").datepicker({
minDate: new Date(),
endDate: "#end" // Would automatically call $("#end").datepicker and set the minDate to whatever #start's selected date is
});
I am considering creating my own branch to try and implement it because I feel that the concept of start and end dates is commonly ignored when datepickers are created but is so frequently needed. 我正在考虑创建自己的分支来尝试实现它,因为我觉得创建日期选择器时通常会忽略开始日期和结束日期的概念,但这种需求非常频繁。
Take a look at the documentation section on linked pickers: https://eonasdan.github.io/bootstrap-datetimepicker/#linked-pickers 看一下链接选择器的文档部分: https : //eonasdan.github.io/bootstrap-datetimepicker/#linked-pickers
In your case you would do: 您的情况是:
$("#start").on("dp.change", function (e) {
$('#end').data("DateTimePicker").minDate(e.date);
});
Try this, 尝试这个,
$("#start").datetimepicker({
minDate: new Date()
}).on("change.dp", function(selectedDate) {
$("#end").datetimepicker({ minDate: selectedDate });
});
If not, try this, 如果没有,请尝试
$("#start").datetimepicker({
minDate: new Date()
}).on("dp.change", function(selectedDate) {
$("#end").datetimepicker({ minDate: selectedDate });
});
Check bootstrap-3-datetimepicker-events-not-firing-up for more info 检查bootstrap-3-datetimepicker-events-not-firing-up以获取更多信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.