which form element triggered QAjaxAction?

thread: 3 messages  |  last: about 5 years ago  |  started: wednesday, february 13, 2008, 8:41 am pst


#1  |  tronics (VIE, AUT) Austria
Wednesday, February 13, 2008, 8:41 AM PST

Hello I have a few formelements that all trigger the same action:

$this->lst1Object->AddAction(new QClickEvent(), new QAjaxAction('functionname'));
$this->lst2Object->AddAction(new QClickEvent(), new QAjaxAction('functionname'));
$this->lst3Object->AddAction(new QClickEvent(), new QAjaxAction('functionname'));


protected function functionname($strFormId, $strControlId, $strParameter) {

}

How can I do these 2 things:

- Identify which element was calling the function?
- Pass a parameter to the function?

Resolved, see below.

Regards,
tronics

#2  |  tronics (VIE, AUT) Austria
Wednesday, February 13, 2008, 1:41 PM PST

-Identify which element was calling the function?
Works very well:

protected function GeneratePersonAnteil($strFormId, $strControlId, $strParameter) {
$this->txtKommentar->Text=$this->GetControl($strControlId)->SelectedValue;

- Pass a parameter to the function?
Works very well:

$this->lstRating->ActionParameter = $intUserId.','.$intContentId;
$this->lstRating->AddAction(new QChangeEvent(), new QAjaxControlAction($this, 'lstRating_Change()'); 


public function lstRating_Change($strFormId, $strControlId, $strParameter) {
list($intUserId, $intContentId) = split(',', $strParameter);

last one taken from http://qcodo.com/forums/topic.php/2730/1//?strSearch=strParameter

#3  |  tronics (VIE, AUT) Austria
Wednesday, February 13, 2008, 4:55 PM PST

Interesting: If you want to use the same Ajaxaction for a checkbox that triggers updates you can also use the property ->ControlId and hand it manually over to the checkbox action parameters.

So you can chill out without duplicating too much coode.

$this->lstTTObject->AddAction(new QClickEvent(), new QAjaxAction('GeneratePersonAnteil'));    
    
$this->chkTTCheckSonstiges->ActionParameter 
   = "lala,".$this->lstTTObject->ControlId;            

$this->chkTTCheckSonstiges->AddAction(new QClickEvent(), new QAjaxAction('GeneratePersonAnteil'));        






protected function GeneratePersonAnteil($strFormId, $strControlId, $strParameter) {
           
list($whatever,$strControlIdOverride) = split(',', $strParameter);
    

$aktuellePerson=$this->GetControl($strControlIdOverride)->SelectedValue;
//instead of $aktuellePerson=$this->GetControl($strControlId)->SelectedValue;

...

}

All the best,
tronics



Copyright © 2005 - 2013, Quasidea Development, LLC
This open-source framework for PHP is released under the terms of The MIT License.