Question

I have a problem with selecting an option from combobox through hitting enter. Two pages are exist, one of these page uses YUI data table, while the other one does not. I have this problem only at the page with YUI datatable. After some digging, I am sure YUI data table causes a problem about enter key events of all other components at the page. If I remove YUI data table from the page, it works without any problem.

I’m using datatable-beta.js for yui-data table and we cannot replace it with a newer version. There are so many things relates to this library, so it is not wanted by the company.

I cannot use enter to select an option at a simple “html select tag” because of this problem.

How do we solve this problem? Does someone face with a similar problem about YI library?

Was it helpful?

Solution

You can override the method in your page so that you won't need to change the original script.

Just override it like below (e.keyCode==13 removed) and your enter issue for that page will be solved.

<script type="text/javascript>
YAHOO.widget.DataTable.prototype._onDocumentKeydown=function(e,oSelf)
{
  if((e.keyCode==27))
  {
        oSelf.cancelEditorData();
  }

}
</script>

OTHER TIPS

I commented out some code blocks to find out which code causes this problem. I eliminated lots of code parts by this way and reached this line:

YAHOO.util.Event.addListener(document,"keydown",this._onDocumentKeydown,this);

This line is at the datatable-beta.js and I don't know why they did something like this. They're handling keydown event of all dom element. That's why I cannot hit the enter to select an option from combobox. Combobox is just a sample, I mean we cannot use enter for any component at the page. Handler method's code is below:

YAHOO.widget.DataTable.prototype._onDocumentKeydown=function(e,oSelf)
{
      if((e.keyCode==27))
      {
            oSelf.cancelEditorData();
      }
      if(e.keyCode==13)
      {
            YAHOO.util.Event.stopEvent(e);
            oSelf.saveEditorData();
      }
}

They're handling escape and enter characters. I do not want to comment out these lines. It may effect other code blocks. I found the problem exactly, but you may still suggest a solution. Because, even if i found the problem, I'm still searching the best way to use enter key without changing orginal script.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top