Javascript 如何在SlickGrid日期编辑器中禁用手动更改日期?
我想强制用户使用SlickGrid中的日期选择器,而不能手动键入日期。这可能吗?我浏览了slick.editors.js并尝试了一些东西,但没有任何运气 这是DateEditorJavascript 如何在SlickGrid日期编辑器中禁用手动更改日期?,javascript,jquery,slickgrid,Javascript,Jquery,Slickgrid,我想强制用户使用SlickGrid中的日期选择器,而不能手动键入日期。这可能吗?我浏览了slick.editors.js并尝试了一些东西,但没有任何运气 这是DateEditor function DateEditor(args) { var $input; var defaultValue; var scope = this; var calendarOpen = false; this.init = function () { $input = $("<INPUT type=
function DateEditor(args) {
var $input;
var defaultValue;
var scope = this;
var calendarOpen = false;
this.init = function () {
$input = $("<INPUT type=text class='editor-text' />");
$input.appendTo(args.container);
$input.focus().select();
$input.datepicker({
showOn: "both",
buttonImageOnly: true,
buttonImage: "../images/calendar.gif",
beforeShow: function () {
calendarOpen = true
},
onClose: function () {
calendarOpen = false
}
});
$input.width($input.width() - 18);
};
this.destroy = function () {
$.datepicker.dpDiv.stop(true, true);
$input.datepicker("hide");
$input.datepicker("destroy");
$input.remove();
};
this.show = function () {
if (calendarOpen) {
$.datepicker.dpDiv.stop(true, true).show();
}
};
this.hide = function () {
if (calendarOpen) {
$.datepicker.dpDiv.stop(true, true).hide();
}
};
this.position = function (position) {
if (!calendarOpen) {
return;
}
$.datepicker.dpDiv
.css("top", position.top + 30)
.css("left", position.left);
};
this.focus = function () {
$input.focus();
};
this.loadValue = function (item) {
defaultValue = item[args.column.field];
$input.val(defaultValue);
$input[0].defaultValue = defaultValue;
$input.select();
};
this.serializeValue = function () {
return $input.val();
};
this.applyValue = function (item, state) {
item[args.column.field] = state;
};
this.isValueChanged = function () {
return (!($input.val() == "" && defaultValue == null)) && ($input.val() != defaultValue);
};
this.validate = function () {
return {
valid: true,
msg: null
};
};
this.init();
}
函数日期编辑器(args){
var$输入;
风险价值;
var范围=此;
var calendarOpen=false;
this.init=函数(){
$input=$(“”);
$input.appendTo(参数容器);
$input.focus().select();
$input.datepicker({
showOn:“两者”,
buttonImageOnly:正确,
buttonImage:“../images/calendar.gif”,
beforeShow:函数(){
calendarOpen=true
},
onClose:function(){
calendarOpen=false
}
});
$input.width($input.width()-18);
};
this.destroy=函数(){
$.datepicker.dpDiv.stop(true,true);
$input.datepicker(“隐藏”);
$input.datepicker(“销毁”);
$input.remove();
};
this.show=函数(){
如果(日历打开){
$.datepicker.dpDiv.stop(true,true.show();
}
};
this.hide=函数(){
如果(日历打开){
$.datepicker.dpDiv.stop(true,true.hide();
}
};
this.position=功能(位置){
如果(!日历打开){
返回;
}
$.datepicker.dpDiv
.css(“顶部”,position.top+30)
.css(“左”,位置.left);
};
this.focus=函数(){
$input.focus();
};
this.loadValue=函数(项){
defaultValue=项[args.column.field];
$input.val(默认值);
$input[0].defaultValue=defaultValue;
$input.select();
};
this.serializeValue=函数(){
返回$input.val();
};
this.applyValue=函数(项、状态){
项[args.column.field]=状态;
};
this.isValueChanged=函数(){
返回(!($input.val()=“”&&defaultValue==null))&&($input.val()!=defaultValue);
};
this.validate=函数(){
返回{
有效:对,
msg:null
};
};
this.init();
}
试试这个:
$input.bind('keydown', function(){ return false });