Ext.button click() method - extjs

ExtJS 4.1.
Is there something like Ext.button.click(); method on Ext.button class?
Is it possible to programmically "click" a button with one method?

Or if you have an MVC structure you can fire the click event of the button, and if you're listening to the event in your controller and have an associated function it will get called.
button.fireEvent('click', button);

The last answer on this forum might give you more insight on how you can do that
here they are-
1)Create the event code in a function and call the function from both sides: btn.on("clic", ...) and from the code you want to simulate the click.
2)Use: btnView.btnEl.dom.click();
from -
http://www.sencha.com/forum/showthread.php?37772-Solved-Programmatically-click-an-Ext.Button

ExtJS 4.2.1
Ext.get('component-id-of-extjs-button').el.dom.click();
Ext.get('toggle-button2').el.dom.click();
works for me.

In case of buttons using handler, you can directly call the function of button.
Considering button is an Ext JS component, you can use:
button.handler(button);
or if you want to reach a function of event 'click':
button.listeners.click(button);
That would also work to call different button events.

Since I needed it for many buttons, it was easier to implement an override on the button class, which adds a click function:
Ext.define('Ext.override.Button',{
override:'Ext.button.Button',
click:function() {
this.getEl().dom.click();
}
})
After this override has been added to the code base, the following works like a charm:
Ext.getCmp("MyButton").click()
Unlike fireEvent or fireHandler, this will work with all kinds of buttons - no matter whether they have a click event or a handler, or whether they are toggle buttons where the clicked button has to be marked as pressed also.

If you need to execute the "handler" of the button, just run this (tested with ExtJS 4.2)
button.fireHandler()

If you want to do this in your test scripts, take a look at my Ext.ux.Test library. If you need it for something other, I would suggest reconsidering your approach.

None of the other answers worked for me, but i found something simplier i think :
var button=Ext.get('the_id_div');
button.dom.click();

document.getElementById("someButtonId").click();

Related

ActionListener-like event on NumericSpinner

Is there anyway to get NumericSpinner value in realtime as selection is made on it? Like adding an ActionListener like event?
I would suggest avoiding that class as it has been deprecated for a while now.
You can use addActionListener on the Spinner instance.

Capture event when md-sidenav is toggled (using md-is-locked-open)

I'm using the Angular Material component framework.
I've defined a page with a md-sidenav called sidebar that is automatically shown (on the left of the screen) if resized to a certain width. This is possible thanks to the directive md-is-locked-open="$mdMedia('gt-sm')".
What I try to achieve seems quite straightforward: I just want to know (have an event triggered) when the sidenav is being shown / hidden (by user, or automatically). I've tried several different solutions, but nothing seem to be working.
I have a plunker that has the same behaviour as what I'm are trying to achieve. In the activate function, I try to capture the events (or what I thought would be events, doesn't seem so because it's not working).
I tried almost all the solutions that were given here and here, but no luck (specially when automatically showing / hiding the sidenav).
Any ideas here?
Thank you very much!
You could use the $mdMedia service in the controller instead of in the view. From the documentation
The media query will be re-evaluated on resize, allowing you to register a watch.
So you can register a watcher for your desired media query size, then call a function when the watcher fires:
$scope.$watch(function(){return $mdMedia('gt-sm');}, function(){
$scope.showSideNav = !$scope.showSideNav;
console.log("SideNav State Change");
});
Then I'd setup the sideNav like this:
md-is-locked-open="showSideNav"
Here is a working example, forked from your Plunker

Set button action in controller

I have a navigation view with one button in the toolbar. Based on the view pushed, the button's label and functionality should chang. I've managed to do this by creating many buttons and activating them as needed (hide/show)
Instead of doing that approach I'd like to have just one button and in the controller change the text and action. Something along these lines:
this.getButton().setHtml("new text");
this.getButton().action = "newaction";
setHtml works, but setting the action doesn't. Examining the button in the console, I see the action changes but when I click it, it responds to the previous action.
Any suggestions on how to approach this?
Thanks
You should use setText instead of setHtml that, err... Doesn't seem to exist! And setHandler to change the handler function.
Alternatively, since you say that you're working in a controller, you can attach a function to the click event of the button and, inside this listener function, decide what action to execute in the current context.

WP7 - Is it possible to automatically launch the camera capture without a button press?

I'm using this code to grab barcodes from the camera:
http://blogs.msdn.com/b/stephe/archive/2011/11/07/wp7-real-time-video-scan-a-barcode-qr-code-in-your-app-using-zxing-lib.aspx
It works fine if it is called from a button press, but if you put it in page load nothing happens, I assume this is a security feature?
Is there any way around it?
Thanks
All must be Ok with Loaded event. Maybe you put code inside constructor instead...

How to catch/handle the window form's hidden/showed events?

In my application I call App.Current.MainWindow.Show()/App.Current.MainWindow.Hide() to show/hide my application but I don't know how to catch the event when the form is hidden/showed. Please help if you know how to!
One of your tags is WPF and the other is WinForms... I'm better with WinForms, so I'll answer for that tag.
The Form.Shown event documentation is here with sample code...
There is no corresponding Form.Hidden event. The best you can do is choose from Form.Closing or Form.Closed or one of the other events.
Added from my comment above
Question - if you're CALLING the Hide and Show in your code, why do you need to capture the events? You already KNOW when it's happening. If you want to run some code inside the form after hiding and closing it, expose the code as a public function, and call the function after showing and hiding the form...

Resources