Opened 8 years ago

Closed 7 years ago

Last modified 4 years ago

#14703 closed defect (fixed)

onInput and "normalization" in TextBoxMixin handleEvent

Reported by: mm Owned by: Douglas Hays
Priority: undecided Milestone: 1.8
Component: Dijit - Form Version: 1.7.1
Keywords: Cc:
Blocked By: Blocking:

Description

I’m trying to implement onInput handler and I have found this logic quite confusing

For numbers onInput is caled twice (for keyydown and keypress) For CTRL+V also called twice (keypress and paste)

Tested in FF

I dont find this simplification.

Please can someone review ?

postCreate: function(){

setting the value here is needed since value="" in the template causes "undefined" and setting in the DOM (instead of the JS object) helps with form reset actions this.textbox.setAttribute("value", this.textbox.value); DOM and JS values should be the same

this.inherited(arguments);

normalize input events to reduce spurious event processing onkeydown: do not forward modifier keys set charOrCode to numeric keycode onkeypress: do not forward numeric charOrCode keys (already sent through onkeydown) onpaste & oncut: set charOrCode to 229 (IME) oninput: if primary event not already processed, set charOrCode to 229 (IME), else do not forward var handleEvent = function(e){

var charCode = e.charOrCode
e.keyCode 229;

if(e.type == "keydown"){

switch(charCode){ ignore "state" keys

case keys.SHIFT: case keys.ALT: case keys.CTRL: case keys.META: case keys.CAPS_LOCK:

return;

default:

if(charCode >= 65 && charCode <= 90){ return; } keydown for A-Z can be processed with keypress

}

} if(e.type == "keypress" && typeof charCode != "string"){ return; } if(e.type == "input"){

if(this.skipInputEvent){ duplicate event

this.skipInputEvent = false; return;

}

}else{

this.skipInputEvent = true;

} create fake event to set charOrCode and to know if preventDefault() was called var faux = lang.mixin({}, e, {

charOrCode: charCode, wasConsumed: false, preventDefault: function(){

faux.wasConsumed = true; e.preventDefault();

}, stopPropagation: function(){ e.stopPropagation(); }

}); give web page author a chance to consume the event if(this.onInput(faux) === false){

event.stop(faux); return false means stop

} if(faux.wasConsumed){ return; } if preventDefault was called setTimeout(lang.hitch(this, "_onInput", faux), 0); widget notification after key has posted

}; array.forEach([ "onkeydown", "onkeypress", "onpaste", "oncut", "oninput" ], function(event){

this.connect(this.textbox, event, handleEvent);

}, this);

},

Attachments (1)

14703.patch (3.3 KB) - added by Douglas Hays 8 years ago.
proposed fix

Download all attachments as: .zip

Change History (21)

comment:1 Changed 8 years ago by Douglas Hays

Resolution: invalid
Status: newclosed

This is working as-designed. The API doc says the event is of type keydown | keypress | cut | paste | input. Some keys are best handled by keydown (ESC) and others by keypress (alpha-numberic). onInput is a general purpose handler to let the user know that something has happened.

comment:2 Changed 8 years ago by Douglas Hays

Milestone: tbd1.8
Resolution: invalid
Status: closedreopened

The keydown event still deals with enhanced keyboard scan codes and not ascii codes like keypress does. Hoever, there are some optimizations that could be made to eliminate keypress events for combinations like ctrl+A that cannot be stopped in keypress, and also to eliminate keydown events for printable keys that are outside the a-z0-9 range.

Changed 8 years ago by Douglas Hays

Attachment: 14703.patch added

proposed fix

comment:3 Changed 8 years ago by Douglas Hays

mm, please review the patch. ctrl+A will come thru keydown and not keypress to prevent the browser from seeing it first. Normal printable keys that relocate on different keyboards should not have keydown events with their random scan codes and will be seen only in keypress. numpad specific scan codes will be ignored unless modified with ctrl/alt/meta.

comment:4 Changed 8 years ago by mm

sorry no time so far, will let you know.

comment:5 Changed 7 years ago by Douglas Hays

Any updated status on testing?

comment:6 Changed 7 years ago by Douglas Hays

Resolution: fixed
Status: reopenedclosed

In [28346]:

Fixes #14703. Change TextBox?'s onInput to be called only once for most keyboard events. Printable keys generate keypress and others keydown. Added automated test.

comment:7 Changed 7 years ago by bill

In [30490]:

convert test to AMD baseless, remove dependency on deprecated widget.connect() method, and add missing d.getTestErrback(), refs #14703

comment:8 Changed 5 years ago by Bill Keese <bill@…>

In 054073823470949ace3003f20fdb66ea5e470670/dijit:

Error: Processor CommitTicketReference failed
Unsupported version control system "git": Can't find an appropriate component, maybe the corresponding plugin was not enabled? 

comment:9 Changed 4 years ago by Bill Keese <bill@…>

In 4b3b6fada5bc7135478b3bd82fefda64a9d4b727/dijit:

Error: Processor CommitTicketReference failed
Unsupported version control system "git": Can't find an appropriate component, maybe the corresponding plugin was not enabled? 

comment:10 Changed 4 years ago by Nick Nisi <nick@…>

In 1ade42e637f4388a8688e61c28f5f2fc6702a605/dijit:

Error: Processor CommitTicketReference failed
Unsupported version control system "git": Can't find an appropriate component, maybe the corresponding plugin was not enabled? 

comment:11 Changed 4 years ago by Bill Keese <bill@…>

In a18736b2d282af4666f03e33562f4ed67a86eab6/dijit:

Error: Processor CommitTicketReference failed
Unsupported version control system "git": Can't find an appropriate component, maybe the corresponding plugin was not enabled? 

comment:12 Changed 4 years ago by Bill Keese <bill@…>

In 563129c4745338d859d4b26460b225ff0a80955c/dijit:

Error: Processor CommitTicketReference failed
Unsupported version control system "git": Can't find an appropriate component, maybe the corresponding plugin was not enabled? 

comment:13 Changed 4 years ago by Bill Keese <bill@…>

In bc4a82d4d017509faededebbbdbad7c6054a25df/dijit:

Error: Processor CommitTicketReference failed
Unsupported version control system "git": Can't find an appropriate component, maybe the corresponding plugin was not enabled? 

comment:14 Changed 4 years ago by Bill Keese <bill@…>

In f3f10cc5be13c3cb2531c5cdbfe53b0fd0b55b3b/dijit:

Error: Processor CommitTicketReference failed
Unsupported version control system "git": Can't find an appropriate component, maybe the corresponding plugin was not enabled? 

comment:15 Changed 4 years ago by Bill Keese <bill@…>

In 2cab35314adc560c3530bc3883954138705ed36a/dijit:

Error: Processor CommitTicketReference failed
Unsupported version control system "git": Can't find an appropriate component, maybe the corresponding plugin was not enabled? 

comment:16 Changed 4 years ago by Bill Keese <bill@…>

In 74445e54eeb74821df470a25140bbbad248fa32c/dijit:

Error: Processor CommitTicketReference failed
Unsupported version control system "git": Can't find an appropriate component, maybe the corresponding plugin was not enabled? 

comment:17 Changed 4 years ago by Bill Keese <bill@…>

In d428c3a5c3cbd6df347010cde62c3190cedab0ae/dijit:

Error: Processor CommitTicketReference failed
Unsupported version control system "git": Can't find an appropriate component, maybe the corresponding plugin was not enabled? 

comment:18 Changed 4 years ago by Bill Keese <bill@…>

In 09f3293ce152ebadeb4df7d2cbae1baf08f107fc/dijit:

Error: Processor CommitTicketReference failed
Unsupported version control system "git": Can't find an appropriate component, maybe the corresponding plugin was not enabled? 

comment:19 Changed 4 years ago by Bill Keese <bill@…>

In 23c79aa383159103bb9e7827c7c3c2b27edb4e07/dijit:

Error: Processor CommitTicketReference failed
Unsupported version control system "git": Can't find an appropriate component, maybe the corresponding plugin was not enabled? 

comment:20 Changed 4 years ago by Bill Keese <bill@…>

In 60065ec5b696c9f00c9c6f1d62333a726aad39a1/dijit:

Error: Processor CommitTicketReference failed
Unsupported version control system "git": Can't find an appropriate component, maybe the corresponding plugin was not enabled? 
Note: See TracTickets for help on using tickets.