Bug Tracker

Opened 6 years ago

Closed 6 years ago

#13787 closed bug (notabug)

Programmatically changing text prevents Change event from being triggered

Reported by: joaop.aires@… Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.9.1
Keywords: Cc:
Blocked by: Blocking:

Description

I've came up with this very interesting "feature". He's my story, step-by-step: 1) I have a TextBox where users enter data. 2) For some reason, I want that data not to exceed 5 characters. 3) To do so, I've implemented a function that, OnKeyUp ensures that by substringing the string whenever it exceeds the max limit. 4) I also need to do something on the Change event (and yes, I only want to do things after the user leaves the TextBox)

What I found out it that, if the function on 3) runs, the Change event will not occur. You can test this behavior here: http://jsfiddle.net/jpaires/dpujx/

Just enter "12345" and leave the TextBox. The console will show a "a-ok" messagem. However, if you enter "123456" the function on 3) will trim the message to "12345" but when you leave the Textbox no Change event seems to occur.

This doesn't sounds like the correct behaviour for the Change event. My interpretation is that the programmatic change to the TextBox is resetting some change "flag".

PS - I know there are other ways of doing this but my main question is why programmatically changing text prevents Change event from being triggered?

Change History (1)

comment:1 Changed 6 years ago by scottgonzalez

Resolution: notabug
Status: newclosed

That's just how the change event works. Try it without jQuery.

Note: See TracTickets for help on using tickets.