GWT event that should be fired whenever textbox.setText() is called - html

I am using GWT textbox.
Whenever textbox.setText() method is called, i want to perform an action in some other class.
ValueChangeEvent is not fired whenever setText() is called.
Is there any event that will be fired or any ways to achieve this?
Please help

You could try to use setValue(String value, boolean fireEvent) method

If you have a look at the TextBox.seText() method, you'll see that, all the way down to the actual DOM, no event is ever generated, so what you want to do simply won't work off-the-box.
I see two options:
Whenever you call setText, you also call the event handler of your choice or, much better
Make your own TextBox that extends TextBox, and override the setText() method so that it first calls super.setText() and then does whatever event generation you'd like

Related

How to deactivate onTick method in Cesium

I have Problem with onTick() method, I have two buttons for two different situations, in each one I will load separate dataSource, just like the czml.html example on Sandcastle. I have two different definition for onTick() method for each button seperately, to do some specific things when we reach at a specific time. In the reset method I am removing entities and dataSources of my viewer, but I cannot remove onTick method implementation.
When I am running my code, the default button is doing perfectly fine, but when I press other button, all those conditions that I mentioned for the first button is also happening at the same time, and it will not let my second onTick method to perform its job correctly. Do you know how I can deactivate the first onTick method?
Take a look at the addEventListener documentation, you'll find two different ways to undo the addition of an event listener: One is to call the matching removeEventListener, and the other is to save the return value from addEventListener and invoke it later.
Here's some code showing both ways. Use whichever option makes more sense for your code, but don't use both at once.
function onTickCallback(clock) {
// ... do stuff with every tick ...
}
var unsubscribeTicks = viewer.clock.onTick.addEventListener(onTickCallback);
function unsubscribeOption1() {
// One option is to call removeEventListener. In this case, you
// don't need to save "var unsubscribeTicks" at all, but you do
// need a reference to the original onTickCallback.
viewer.clock.onTick.removeEventListener(onTickCallback);
}
function unsubscribeOption2() {
// The other option is to save the return value of addEventListener,
// and later invoke it. This could be a cleaner option if the
// onTickCallback was declared anonymously inline.
unsubscribeTicks();
}

Flex event listener for Alert show

Is it possible to add an event listener for Alert.show?
So that every time an alert box is shown I can call a function to hide an iframe.
I think you will get stuck since event dispatching/listening will require using an instance of a class to be the dispatcher, which is not the case when using the static .show().
However, I guess you could manually dispatch an event every time you want to close your iframe and display an alert (both could be done by the event dispatched).
You could as well create your own class that would have a .showAlert function performing both the event dispatching and the regular Alert.show(). This requires your custom class to be instantiated but the instance could also be stored in a Singleton so you don't have to recreate a new one every time you want to display your Alert.
Alert.show will return you the instance of the alert object. Use the object to add event listeners on the alert.
var alert:Alert = Alert.show("contente");
alert.addEventListener(Event.Close, function(e:Event):void{
// TODO
);

How do you replace a listener in dart?

I have a class that creates a button and connects a listener to the click event. In a sub class I'd like to replace the superclass handler. This code adds a listener:
row.query("[value='Save']").onClick.listen(handleNewAlert);
How do I remove the existing listener?
The Stream.listen() method returns a StreamSubscription object. Call StreamSubscription.cancel() to cancel the event listener.
var subs = element.onClick.listen((e) => print(e));
// Remove the listener.
subs.cancel();
// Add another listener.
element.onClick.listen((e) => print(e));
See this article for more information.
Greg's answer describes how to unsubscribe from the event source.
This is correct, but IMO a bit awkward, as you need to keep the subscription instance around in case that any derived class wants to cancel it, or you need to provide a method for this on the base class if you want to hide the details.
As you say that you want to replace the handler, which I understand as providing a different implementation, a simpler approach is to simlpy override handleNewAlert method in the derived class.
Of course, it won't work if instead of method name you have specified an anonymous function, as it obviously can't be overridden, but in the scenario shown in your example, this might be an easier approach.

Actionscript 3 - Is it ok to have a bunch of code inside an event listener handler?

I'm creating a GUI, but only if things go ok, so can i
addEventListener(Event.Complete, go) to something and in the go function create my GUI (grafical elements such as labels, lists, squares)?
Is it ok to do that?
Technically it's fine. crooksy88 gives a good example of supplying a default value for the event parameter to make the function more versatile.
However, for the sake of semantics, clarity, and maintenance I would usually prefer to separate things more. So mine might be set up more like this:
protected function onLoadComplete(e:Event):void {
initAppSettings();
createUI();
startApp();
}
It makes it much easier to understand the flow of the app and what each part does just by reading the function names. When I come back to this later, I'll know that my UI is created in the function named createUI and not have to figure out that it gets created in an event handler with a cryptic name like go or handleEvent.
Also, if I want to change the flow of my app, say to pop up a dialog once the load is complete before the UI is created, I just have to move around some function calls, instead of moving around large chunks of code.
Yes that is perfectly fine. The go function isn't part of the event listener.
function go(e:Event):void {
// do something
}
The sample above requires the event parameter from the listener (e:Event).
But you can modify the function so that the parameter is optional so you can call the go function any time you want
function go(e:Event = null):void {
// do something
}
The example above will be triggered by the listener and also by typing
go();

How to hook a keyboard event handler onto an INPUT element with jQuery?

I want to attach my own key event handler to an INPUT that already has another event handler attached to onkeydown. Essentially, I want to receive a key event before all the other handlers and check if the user pressed a certain key -- if yes, I want to perform some functions and discard the event, if no, I want to pass it along to the other handler(s).
How can I do this with jQuery?
If you are loading a 3rd party script or jQuery addon you can just load your script or function first. If you do that then you can use something like this without the mess of unbinding and rebinding event handlers.
// your possible interceptor code
$("#awesome").keydown(function(e) {
if (e.keyCode < 70) {
e.stopImmediatePropagation();
console.log("BLOCKED!!!");
};
});
// possible 3rd party event code loaded after your code
$("#awesome").keydown(function(e) {
console.log("3rd party:"+e.keyCode);
});
Example webpage => http://mikegrace.s3.amazonaws.com/forums/stack-overflow/example-key-event-interception.html
Example output of Firebug console
jQuery stopImmediatePropagation() documentation
According to the jQuery bind() documentation:
"When an event reaches an element, all handlers bound to that event type for the element are fired. If there are multiple handlers registered, they will always execute in the order in which they were bound."
So it looks like you will have to unbind the other handlers, bind yours and then add the others back if you want yours to run first.
There is some good information in this thread with respect to that:
jQuery: Unbind event handlers to bind them again later