Javascript Dojo组合框[Enter]键事件终止数据存储响应

Javascript Dojo组合框[Enter]键事件终止数据存储响应,javascript,combobox,dojo,Javascript,Combobox,Dojo,我已将dojo组合框配置如下: this.autoComplete = new dijit.form.ComboBox( { id : this.name + "_term", name : "search_id", store : this.dataStore, searchAttr : "term", pageSize : "30", searchDelay:500, value : this.config.inputText, hasDownArrow :

我已将dojo组合框配置如下:

this.autoComplete = new dijit.form.ComboBox( {
  id : this.name + "_term",
  name : "search_id",
  store : this.dataStore,
  searchAttr : "term",
  pageSize : "30",
  searchDelay:500,
  value : this.config.inputText,
  hasDownArrow : false
}, this.name + "_term");
这里的问题是,当用户输入搜索词并在500毫秒前点击[Enter]时,服务请求将被取消(复制和粘贴搜索词时很常见)。我希望它忽略[Enter]事件,直到请求完成并在下拉列表中显示选项。然后,用户可以再次按enter键提交响应中的第一项

希望得到一些关于如何处理这种情况的建议。我已经查看了dijit.form.ComboBox的api,但没有看到任何令人信服的解决方法。请注意,如果使用FilteringSelect而不是ComboBox,则存在完全相同的行为。有趣的是FilteringSelect将此场景视为由“invalidMessage”参数处理的错误。我不理解将此视为错误的好处。

我已经(暂时)通过重写_onKeyPress函数对dijit.form.ComboBox进行了修补,从而解决了这个问题。我正在使用DojoV1.5,并注意到v1.6将_onKeyPress更改为_onKey。所以升级显然会破坏一切

我更新了[Enter]事件处理,如下所示:

  case dk.ENTER:
    // prevent submitting form if user presses enter. Also
    // prevent accepting the value if either Next or Previous
    // are selected
    if(highlighted){
      // only stop event on prev/next
      if(highlighted == pw.nextButton){
        this._nextSearch(1);
        dojo.stopEvent(evt);
        break;
      }else if(highlighted == pw.previousButton){
        this._nextSearch(-1);
        dojo.stopEvent(evt);
        break;
      }
    }else{
      if (!module.autoComplete.item) {
        doSearch = true;
      }
      // Update 'value' (ex: KY) according to currently displayed text
      this._setBlurValue(); // set value if needed
      this._setCaretPos(this.focusNode, this.focusNode.value.length); // move cursor to end and cancel highlighting
    }
    // default case:
    // prevent submit, but allow event to bubble
    evt.preventDefault();
    // fall through
    break;
有关守则是:

if (!module.autoComplete.item) {
  doSearch = true;
}
我基本上是告诉它只有在自动完成对象实例存在并且还没有收到任何项目时才进行搜索。这是一个丑陋的黑客,但它正在解决目前的问题。我仍然希望得到一些关于如何更好地处理这个问题的建议