Opened 14 years ago

Closed 14 years ago

Last modified 12 years ago

#499 closed defect (invalid)

event system can not managed boolean return values

Reported by: anonymous Owned by: anonymous
Priority: high Milestone:
Component: Core Version: 0.2
Keywords: event cancel Cc: pabloa@…
Blocked By: Blocking:

Description

I try to connect all the input type text to an event to validate input. When I find a key that I do not like I try to cancel the key, but dojo does not cancel the event when I return false.

Example

function controlarTextBox() {
  var textBoxes = document.getElementsByTagName( 'input');
  cant = textBoxes.length;
  for( n = 0 ; n < cant; n++) {
    if( textBoxes.item( n).getAttribute( 'type') == 'text') {
      dojo.event.connect( textBoxes.item( n), "onkeypress", "handleOnKeypressInputText");
    }
  }
}

function handleOnKeypressInputText( evt) {
  var unicode = evt.charCode ? evt.charCode : evt.keyCode;
  if( unicode == 39 || unicode == 97) {
    return false;
  } else {
    return true;
}

controlarTextBox();


The sample try to invalidate the keys "a" and "'", but it does not function as I guess.

I try to fix but dojo is a bit dark to me :-)

In the meantime I replace the dojo call for this:

textBoxes.item( n).onkeypress=function( evt) {
   if( evt) { 
      var miEvento = evt;
   } else {
      var miEvento = window.event;
   }
   return handleOnKeypressInputText( miEvento); 
};

This link the event call with the waited results.

Regards

Pablo

Change History (3)

comment:1 Changed 14 years ago by anonymous

Milestone: 0.2.2release0.3release
Priority: normalhigh

comment:2 Changed 14 years ago by alex

Resolution: invalid
Status: newclosed

The event system attaches listeners, not interceptors. You may be able to handle it with around advice, but regardless it is not a bug in the event system.

comment:3 Changed 12 years ago by (none)

Milestone: 0.3release

Milestone 0.3release deleted

Note: See TracTickets for help on using tickets.