RemoveAllActions isn't working

Login or register to post comments
8 replies [Last post]
LaCeja's picture
Offline
Joined: 11/04/2009

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.

Offline
Joined: 08/06/2010

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';
}

alex94040's picture
Offline
Joined: 11/06/2008

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.

LaCeja's picture
Offline
Joined: 11/04/2009

Thanks Mile. It should have been:

$this->btnLinkEditOrder->RemoveAllActions('click');

I was using the html "onclick" by mistake.

Thanks again!

LaCeja's picture
Offline
Joined: 11/04/2009

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.

alex94040's picture
Offline
Joined: 11/06/2008

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);

Offline
Joined: 08/06/2010

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

alex94040's picture
Offline
Joined: 11/06/2008

Great catch! Can you open a ticket, please? If you feel adventurous, make a patch too! :-)

Offline
Joined: 08/06/2010

http://trac.qcu.be/projects/qcubed/ticket/696
I dont like making patches.