Javascript 限制datetimepicker上的过去日期
我没有问题限制我的一些Javascript 限制datetimepicker上的过去日期,javascript,jquery,angularjs,datepicker,Javascript,Jquery,Angularjs,Datepicker,我没有问题限制我的一些日期时间选择器,但这一个是持久的,我尝试在angularjs中执行此操作,日期时间选择器位于数据表中,我将其设置为: { data: "next_action_date", name: "next_action_date", render: (data, type, row, meta)-> initValue = data
日期时间选择器
,但这一个是持久的,我尝试在angularjs
中执行此操作,日期时间选择器
位于数据表中,我将其设置为:
{
data: "next_action_date",
name: "next_action_date",
render: (data, type, row, meta)->
initValue = data
if data
initValue = "'" + data + "'"
if row.is_editable
return '<div class="input-control text" data-role="datepicker"
ng-controller="ContactDateCtrl"
ng-init="init(' + row['pk'] + ', ' + initValue + ')" data-format="mmmm d, yyyy">
<input type="text" ng-model="contactDate" ng-change="onChange()">
<button class="button"><span class="mif-calendar"></span></button>
</div>';
else
return data;
}
(function() {
var app;
app = angular.module('cms.sales');
app.controller('ContactDateCtrl', [
'$scope', '$http', function($scope, $http) {
var nextContactDateUpdateFailed, nextContactDateUpdateSuccess;
$scope.contactDate = null;
$scope.leadContactPk = null;
$scope.init = function(leadContactPk, nextContactDate) {
nextContactDate = new Date();
$scope.leadContactPk = leadContactPk;
if (nextContactDate) {
return $scope.contactDate = nextContactDate.getFullYear() + '-' + (nextContactDate.getMonth() + 1) + '-' + nextContactDate.getDate();
} else {
return $scope.contactDate = "";
}
};
$scope.onChange = function() {
var data;
data = {
contact_date: $scope.contactDate,
lead_pk: $scope.leadContactPk
};
return $http.post("/sales/update_contact_date/", data).then(nextContactDateUpdateSuccess, nextContactDateUpdateFailed);
};
nextContactDateUpdateSuccess = function() {
return ClientNotifications.showNotification("Success", "Next communication date was updated", "success");
};
return nextContactDateUpdateFailed = function() {
return ClientNotifications.showNotification("Alert", "Failed to update next communication date", "alert");
};
}
]);
}).call(this);
现在这并没有限制我的datetimepicker
它只是返回这个时间格式2017-5-23
,我不确定还能做什么,还有什么我可以做的吗?这个限制会起作用,我在我的项目中使用datetimepicker
,有人能帮我正确限制吗,谢谢。只需添加格式即可
$(function(){
$("#datepicker").datepicker({
format: 'mmmm d, yyyy',
minDate:new Date(Date.now()-(86400000 * n)) // just for min date and 'n' is the number of previous days to be allowed
});
});
或者自定义输入的ng模型
在if条件下做类似的事情
var tempDate = nextContactDate.toString().split(' ');
tempDate = tempDate[1] + " " + tempDate[2] + ", " + tempDate[3];
$scope.tempDate = tempDate;
$scope.contactDate = nextContactDate;
如果将日期更改为字符串,则可能会丢失控制器中的句柄。因此,将其存储在临时$scope.tempDate
中以显示在视图中,并使用主变量,即$scope.contactDate
执行逻辑
确保输入的ng model
应为$scope.tempDate
第一选择更好为什么你不能使用
棱角材质
日期选择器?因为我们在项目中使用了这个日期选择器--你只是想将过去的日期限制在某一天吗?@Mr_Perfect,看看这个例子,这就是我想要的,它正在项目中的其他日期选择器
上工作,请注意,时间需要以这种格式显示在2017年1月13日metroui DATECOPKER
中,这是