Opened 7 years ago

Closed 7 years ago

#16102 closed defect (wontfix)

dijit._HasDropDown _onKey: charCode always '0', isChar always 'false', charOrCode missing

Reported by: Paul Christopher Owned by: Paul Christopher
Priority: undecided Milestone: tbd
Component: Dijit Version: 1.8.0
Keywords: Cc:
Blocked By: Blocking:

Description

We have been running into a severe issue when uprading from 1.8.b1 to the official 1.8 release.

Our widget (see reduced test case) inherites from ValidationTextBox and _HasDropdown. In the _onKey handler's event object, charCode is always zero, regardeless which key you press. charOrCode has been removed? I cannot find it in the event object anymore. isChar is always 'false' even if you press PAGE_DOWN. If you enter 'a' it gives you charCode 65. If you enter 'A' it gives you 65 and the shift-flag is set. There is no way to get the real charCode of a capital 'A' in the event object.

Is this all intended?

At the moment, there seems to be no neat way to distinguish character/number input in the text box from control key input (as I could still do in 1.8.b1, see code in the test case).

Attachments (1)

testDojo.htm (2.0 KB) - added by Paul Christopher 7 years ago.

Download all attachments as: .zip

Change History (5)

Changed 7 years ago by Paul Christopher

Attachment: testDojo.htm added

comment:1 Changed 7 years ago by bill

Component: Dijit - FormDijit
Owner: changed from Douglas Hays to Paul Christopher
Status: newpending

Yes, the event passed to _onKey() is now a keydown event, rather than a synthetic keypress event generated from dojo.connect(). IIRC, it was in order to workaround a bug with dojo.connect() and IE.

I'm unclear from your test case what you are trying to do. If you are trying to do an action for a non-printable character like backspace, then you could still override _onKey(), but look at evt.keyCode.

If you are trying to do an action for a printable character like 'A', I think the quick fix for you would be to do your own dojo.connect() on "keypress" on this.focusNode, to call your handler function. For 2.0 dojo.connect() will go away, so the long term solution for you is to call dojo/on on the "keypress" event, which will generate an event object with charCode, but not charOrCode.

Does that work for you?

comment:2 Changed 7 years ago by Douglas Hays

or you could try onInput from _TextBoxMixin.js

onInput: function(event){
        // summary:
        //              Connect to this function to receive notifications of various user data-input events.
        //              Return false to cancel the event and prevent it from being processed.
        // event:
        //              keydown | keypress | cut | paste | input
        // tags:
        //              callback
},

charOrCode will be set if applicable.

comment:3 Changed 7 years ago by Paul Christopher

Status: pendingnew

Bill,Doug,

Thank you very much for your quick reply -- especially since we are about to finish our first Dojo project.

Of course the test case is reduced to its bare essentials and may look meaningless. Anyhow, it is good to know that it is not a Dojo bug. And at least I understand the reason now, why I do not get a charCode.

I think the easiest option for me is to analyze the passed keyCode then - as we already do as a workaround. Using onInput or connecting to keypress might be problematic, since _onKey handles the opening and closing of the drop down and I do need to focus items inside the drop down.

comment:4 Changed 7 years ago by bill

Resolution: wontfix
Status: newclosed

Glad you have a workaround. Sounds like we can close this. I think it makes sense for you to look at keyCode anyway, since you are dealing with non-printable characters.

Note: See TracTickets for help on using tickets.