-
30 May 2012 8:10 AM #1
Default butons on dialog
Default butons on dialog
Hi!
How can I set typical default buttons on a dialog to reuse their expected behavior:
- OK button (reacts on ENTER pressed while any field on the form is in focus)
- Cancel button (does the same as ESC key)
Another related question... Which event is raised when ESC is pressed, just before closing the dialog? This would be a place to put "Are you sure?" msg box..
Thanks!
-
30 May 2012 8:55 AM #2
Where you looking for something like this?
Regards,Code:Ext.Msg.prompt('Name', 'Please enter your name:', function(btn, text){ if (btn == 'ok'){ // prompt and/or process text value and close... } });
Scott
-
31 May 2012 12:42 AM #3
@scottmartin,
no, that's not what I want.
I have a custom-made dialog (actually a lot of them, every app does) and among other buttons, it has a default OK-button (which sometimes is "Save" or "Procede", "Confirm" or just "Ok") and a default CANCEL-button (to cancel the operation and close the dialog upon confirmation msg-box).
OK-button can also be "pressed" by pressing enter anytime, while the dialog is in focus.
CANCEL-button can be "pressed" by pressing ESC (in Ext JS this works in case of a little "x" button on the dialog's caption bar)
I hope this clarifies my problem.
Thank you all in advance!
-
31 May 2012 5:52 AM #4
Perhaps you are referring to something like this?
Regards,Code:var formSearch = new Ext.FormPanel({ items: [ { xtype: 'textfield', handler: searchSubmit } ], keys: [ {key : [10,13],fn:searchSubmit} ], // submit on enter buttons: [ { text: 'Search', handler: searchSubmit }, { text: 'Reset', handler: function() { .. } } ] }); function searchSubmit() { // execute search }
Scott.
-
1 Jun 2012 5:09 AM #5
@scottmartin,
Thank you again, we are getting closer.
I see another problem now, related with the way I catch button events.
I have a controller class who is responsible for button clicks and other events... For example, my loginDlg has a button "login" and the corresponding controller catches it the following way:
So, in order to implement your solution, I would have to call the controller's onLoginClicked() method from the View... Is that possible?Code:this.control({ 'login #btn_login': { click: this.onLoginClicked } });
Or I should change the whole logic and instead of catching the event this way, I could fire it from the view and listen to them in the controller...
What do you think?
-
1 Jun 2012 7:39 AM #6
You can assign action: 'loginOk' to your view button and then in your controller
#btn_logon[action=loginOk]
Scott.
-
4 Jun 2012 1:41 AM #7
Hi again Scott!
If I understand your idea well, it won't resolve my initial problem. Iw will work for the button click, but what happens with the key event?
How can I assign the same handler function (defined in the controller, see my example code) with both events (buton click AND the key 13 press while anywhere on the form)?


Reply With Quote