Spark Button - why doesn't pressing the enter key fire click event? - apache-flex

I'm a little confused as to why this isn't the default behaviour?
So, how do I detect the enter key being pressed on my button and fire the click event handler? (For example on a TextInput field there is an 'enter' event)
Thanks

EDIT: Ignore everything I posted before.
You can use the keyDown event on the spark button and create an event handler using KeyboardEvent.
<s:Button label="Submit" keyDown="enter_pressed(event)" id="submit" click="submit_clickHandler(event)"/>
protected function enter_pressed(event:KeyboardEvent):void {
if(event.charCode == Keyboard.ENTER){
submit.dispatchEvent(new MouseEvent(MouseEvent.CLICK));
}
}

EDIT : rollbacked to original post, event will only be fired if button is selected anyways
The enter event is fired when users sets focus on the button and has nothing to do with the keyboard enter key. If I'm not mistaken, the default key for activating a button in Flash is spacebar. You could use enter by doing something like this :
myButton.addEventListener(KeyboardEvent.KEY_DOWN, onMyButtonKeyDown);
private function onMyButtonKeyDown(event:KeyboardEvent):void
{
//simulate click if enter pressed
if(event.keyCode == Keyboard.ENTER)
myButton.dispatchEvent(new MouseEvent(MouseEvent.CLICK));
}

Related

ZKOSS: onClick() working differently for mouse click vs mouse tap

I am trying to disable double clicking a Help label which is an anchor to open the Help window.
<p:a id="helpClick" onClick="help()">
<label value="Help" style="color:#FFFFFF;" />
</p:a>
When onClick() event is triggered once, either by Mouse click or Tapping the touchpad once, the help() method is being invoked.
void help() {
flag = true;
this.helpClick.setDisabled(true);
Window popupWindow = null;
popupWindow = (Window) Executions.createComponents("/zul/mainHelp.zul",
null, null);
this.popupWindow.setClosable(true);
popupWindow.addEventListener("onClose", new EventListener() {
void onEvent(Event event) throws Exception {
this.helpClick.setDisabled(false);
}
});
}
is the code which i added to handle the anchor tag with the id helpClick.
This is working perfectly fine when i use mouse clicks. For the first click, the window gets opened and simultaneously the Label is not taking any more click events.
When i try the same with mouse tap(using the touchpad), two single clicks are being triggered.
I have used onClick() to capture the event.
I am trying to disable the Label once it is clicked and the window is opened. Only after the window gets closed, i am enabling the label.
This is working totally fine when i use mouse clicks but not when i use tap.
With tapping, the label is taking multiple clicks which isnt the case with Mouse Click.
Without seeing code it's difficult to provide advice but maybe you can capture the onDoubleClick event and ignore it or forward it to the to the same listener as your onClick event.
... forward="onClick=onHelpClick,onDoubleClick=onHelpClick" ...
After question edit:
It sounds like a bug if you can double click a disabled component. One thing you could try is set your link to autodisable <p:a id="helpClick" onClick="help()" autodisable="self"> as per A component documentation

I tried to disable the button after the first click.it's working for me now. when the dialog box closed i want the button enabled again

void CMyViewerDlg::OnBnClickedShow()
{
m_DCM.Create(IDD_TAG, this);
m_DCM.ShowWindow(SW_SHOW);
BOOL isOn = true;
if (isOn == false)
{
GetDlgItem(IDC_SHOW)->EnableWindow(TRUE);
}
else
{
GetDlgItem(IDC_SHOW)->EnableWindow(FALSE);
}
}
now the button is disabled after the first click..i want to enable the button again when i close the dialog box..help me to slove this problem..
This is not meant to replace the existing answer but it is based on the comments.
You can use the Classwizard to add custom message handlers. I create a GUID and attach that to WM_APP and use registered messages.
This is a non modeless dialog. So you have to keep track of it on your own. The easiest way would be to send a WM_APP+n message to the parent window/dialog, when the dialog receives the OnDestroy or OnClose event. The parent dialog can handle this message and disable the appropriate button.
Another method is just setting a timer. In the timer you can check if m_DCMTagDlg.m_hWnd is still not NULL. If it reaches NULL just disable the button.

jQuery UI dialog increasingly calling the submit callback

I took the JQuery UI dialog form sample from JQuery UI website.
Since I wanted that, once the dialog is opened and the form is displayed, that pressing the key submits the form, I added the following in the onReady() :
$.extend($.ui.dialog.prototype.options, {
open: function() {
var $this = $(this);
// focus first button and bind enter to it
$this.parent().find('.ui-dialog-buttonpane button:first').focus();
$this.keypress(function(e) {
if( e.keyCode == 13 ) {
$this.parent().find('.ui-dialog-buttonpane button:first').click();
return false;
}
});
}
});
This does perfectly the trick (I mean the click() is triggered when it has to), but the following occurs :
When the form is first submited through a press on the key, the submission is performed once.
If I reopen the dialog, and submit it again with a press on the key, the form is submitted twice.
If I reopen the dialog, and submit it again with a press on the key, the form is submitted three times, and so on...
This can be tested with the following fiddle :
http://jsfiddle.net/fWW2E/
Let me add that doing so by clicking on the dedicated "Submit" button works properly, this fails only when pressing the key is involved.
Any ideas ?
Thank you !
Because since you're assigning this on "open" and your buttons are "closing" the dialog.
When this gets called though:
$('something').dialog('close');
doesn't actually remove the element, it just hides it. So the next time you click to open up a "new" dialog, you're really just showing the first one again. However the "open" event is getting fired again every time it's opened, which is adding a new keypress handler onto it.
Here's the fiddle. I actually write out to the console an array of the current handlers on that element. You'll see everytime you open the dialog that there is another keypress handler.
DEMO

Call click event of button who called pop up when model pop up window is closed

I have two buttons viz. save and update. On both buttons, I am opening pop-up window using Model Pop-up extender. The Pop-up has "ok" as close button. Now what I want is when user clicks on the "Ok" button in the pop-up, it should call the OnClick_save() or OnClick_update() depends on the button who called pop-up.
That means, when user clicks on save button, it will open pop-up window. After entering password in the pop-up window when user click on the Ok button, it should go to the OnClick_save() event. Same thing should happen for update button. How can I do so...???
You can use hidden controls for pop up's OK and Cancel button, and show/hide modal popup programatically. before/after doing so you can call your desired methods or whatever you want to do.
You can do this using event handler..
public delegate void MyEventHandler(object sender, EventArgs e);
MyEventHandler handler = MyEvent;
if(handler != null)
{
handler(this, e);
}
or
this.button1.Click += new System.EventHandler(this.button1_Click);
Or
Write a common method which can invoke from save_click event or ok_click
If you find it useful, please mark it as your answer else let me know...

How can I show a warning before a radiobutton changes in flex?

In my flex app I have some radio buttons. When a user clicks the radio button, I want to popup an Alert, and if the user clicks ok the radio button will change, otherwise their change will be discarded.
How do I accomplish that? I tried event.preventDefault(); while handling the click event, but that didn't do anything. Any other ideas?
Listen to the change event.
If the new value of selected is true, set it to false and show the popup
Update the selected value based on the result of popup.
You could listen for the valueCommit-event and try to stop the behaviour (changing the value) in an event handler. There you can also create a popup...
Listen for the MouseEvent.MOUSE_DOWN event and in your handler do the following:
function myHandler(event:MouseEvent) : void {
event.preventDefault();
event.stopImmediatePropagation();
// statements
}

Resources