【问题标题】:How to disable manually changing date in SlickGrid Date Editor?如何在 SlickGrid 日期编辑器中禁用手动更改日期?
【发布时间】:2014-05-03 13:55:38
【问题描述】:

我想强制用户在 SlickGrid 中使用日期选择器,并且不能手动输入日期。这可能吗?我浏览了 slick.editors.js 并尝试了一些东西,但没有任何运气?

这里是日期编辑器。

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();
}

【问题讨论】:

    标签: javascript jquery slickgrid


    【解决方案1】:

    试试这个:

    $input.bind('keydown', function(){ return false });
    

    【讨论】:

      猜你喜欢
      • 2014-04-25
      • 1970-01-01
      • 2012-02-23
      • 2018-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多