RemoveAllActions isn't working
Tue, 01/11/2011 - 22:01
I'm having a problem with RemoveAllActions. I have set an QJavascriptAction on a button, which I later remove, with RemoveAllActions, but the actions isn't being removed. For example:
$strJavaOpen = "window.open('".__VIRTUAL_DIRECTORY__ . __FORM_MYFORMS__."/orderhdrs_edit.php/".$this->txtOrderNo->Text."/N')";
$this->btnLinkEditOrder->AddAction(new QClickEvent(), new QJavascriptAction($strJavaOpen));The above action obviously opens a new window (browser tab), using Javascript. That works fine. However, later, based on some other user action, I remove the action, but it doesn't get removed. Example:
$this->btnLinkEditOrder->RemoveAllActions('onclick');I'd like some guidance on what I'm doing wrong.
Thank you.

looks to me like wrong parameter.
/**
* Removes all events for a given event name.
*
* Be sure and use a QFooEvent::EventName constant here
* (QClickEvent::EventName, for example).
*
* @param string $strEventName
*/
class QClickEvent extends QEvent {
const EventName = 'click';
}
Moreover - instead of specifying the parameter as a string, a much safer way to prevent this sort of issues is to write QClickEvent::EventName, instead of 'click' directly.
Thanks Mile. It should have been:
$this->btnLinkEditOrder->RemoveAllActions('click');I was using the html "onclick" by mistake.
Thanks again!
Alex, yes that was the first thing I tried, but it failed. I coded it like this:
$this->btnLinkEditOrder->RemoveAllActions(QClickEvent::QJavascriptAction);
That gave me an error, but can't remember what it was. Should "QJavascriptAction" have been something else?
Thanks.
Laceja, I don't quite understand your code snippet - QClickEvent does not have a constant called QJavaScriptAction. It does have a constant named EventName. So it should have been something like
$this->btnLinkEditOrder->RemoveAllActions(QClickEvent::EventName);I found 2 more in v2.0.2 didnot check if they work.
$this->RemoveAllActions('onclick');
QDataGridBase.class.php line 757
and
QPaginatorBase.class.php line 141
Great catch! Can you open a ticket, please? If you feel adventurous, make a patch too! :-)
http://trac.qcu.be/projects/qcubed/ticket/696
I dont like making patches.