Feature #3631
closedAdd onInput() event to WFormWidget
0%
Description
Hi All,
I'm trying to write code that gets an event any time the text in a WTextArea and a WLineEdit changes. I'm not content with waiting for the cursor to leave or enter to be pressed etc, as the content of the control must be written to the database as the control's content is changed.
WFormWidget has a changed() event, but this is only fired when the focus is lost etc, I need an event that should be fired any time text() will give a different result. For some time we have been using OnKeyUp events() but this has several problems:
- we get many events when there is no change to the text, such as, pressing arrow keys and the like.
- crucially, we don't get events when the field is pasted into using the right-click menu from the mouse.
In fact, there appears to be no event that will be triggered immediately after the right-click paste or right-click cut menu options are selected. I suggest changed() should be fired any time the result of text() has changed, however this might break code, so perhaps a new event can be created, though I can't think of a much better name than "changed". Perhaps a flag could be added something like setFineGrainedChangeEvents( bool ).
In the meantime can anyone suggest a workaround for this?
Updated by Jesse Pepper about 10 years ago
By the way, I wonder if this should be considered a bug?
Updated by Wim Dumon about 10 years ago
There seems to be an 'onpaste' event in some browsers, which is non-standard and may have issues. A quick work-around may be:
edit->setAttribute("onpaste", "setTimeout(function(event) {var _this=this; function(){_this.onchanged(event);}}, 0);");
(untested)
BR,
Wim.
Updated by Jesse Pepper about 10 years ago
Hi Wim,
I take it you are suggesting this as a workaround? Can you see the justification for a simple server side changed() event that is triggered every time the result of text() is changed?
Jesse
Updated by Wim Dumon about 10 years ago
Hey Jesse,
In order to avoid confusion for the users of Wt, we most likely won't change the behavior of the current changed signal, since it maps now on what HTML does.
The signal you suggest seems worth to be considered for addition to me, but without further investigation I'm afraid that the need use non-standardized events may be a hell to get it implemented properly.
Best regards,
Wim.
Updated by Jesse Pepper about 10 years ago
Hi Wim,
Doesn't the HTML5 onInput() event do exactly what's necessary? It's supported by all major browsers. See here: http://www.w3schools.com/tags/ev_oninput.asp
Jesse
Updated by Koen Deforche about 10 years ago
- Subject changed from Missing proper changed() event for WFormWidget to Add onInput() event to WFormWidget
- Status changed from New to InProgress
- Assignee set to Koen Deforche
Updated by Koen Deforche over 9 years ago
- Status changed from InProgress to Resolved
Updated by Koen Deforche over 9 years ago
- Status changed from Resolved to Closed