QRadioButtonList QServerAction
Sun, 03/20/2011 - 04:12
Hey guys,
Been a while. I'm using a Radio Button List. When I make a selection of the radio button and run the QServerAction function it isn't setting the checked value for the value I selected correctly when the page displays again.
This works fine for check boxes but not for the Radio buttons.
Do I need to add code to my QServerAction function to capture what was the selection and make this the "Checked" selection when displaying the Qform again?
Cheers
Jason

Hello jasonx, I dont think you need to do that. Since the QForm State is maintained, it should keep the checked value. Probably some intermediate processing is changing that, would you mind showing the code so I can determine if that is the case?
Hi stumbled on that post after experiencing the same issue.
Here is the smallest code I was able to isolate to replicate the issue. It happen on a simple QForm with the radio button list as the only control.
In the example, you will see that whatever radio value is selected, when you click on the Server Action, you get the same value out of the alert option and the radio button is defaulted to value 1 every time.
<?php
require ('../qcubed.inc.php');
if (!isset($this)) {
class AdminForm extends QForm {
public $rad;
public $btnServer;
public $btnAjax;
protected function Form_Create() {
parent::Form_Create ();
$this->rad = new QRadioButtonList ( $this );
$objListItem = new QListItem("1", 1,true);
$this->rad->AddItem($objListItem);
$objListItem = new QListItem("2", 2,false);
$this->rad->AddItem($objListItem);
$objListItem = new QListItem("3", 3,false);
$this->rad->AddItem($objListItem);
$this->btnServer = new QButton ( $this );
$this->btnServer->Text = "Server Action";
$this->btnServer->AddAction ( new QClickEvent (), new QServerAction ( "btnClick" ) );
$this->btnAjax = new QButton ( $this );
$this->btnAjax->Text = "Ajax Action";
$this->btnAjax->AddAction ( new QClickEvent (), new QAjaxAction( "btnClick" ) );
}
public function btnClick() {
QApplication::ExecuteJavaScript ( 'alert("' . $this->rad->SelectedValue . '")' );
}
}
AdminForm::Run ( 'AdminForm', __FILE__ );
return ;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php _p(QApplication::$EncodingType); ?>" />
<title>Sample QForm</title>
</head>
<body>
<?php $this->RenderBegin(); ?>
<?php $this->rad->Render(); ?>
<br><br>
<?php $this->btnServer->Render();?>
<br>
<?php $this->btnAjax->Render();?>
<br>
<?php $this->RenderEnd(); ?>
</body></html>
So far, I haven't found any solution ither than using the AjaxAction instead of the Server action.
Hope this help.
Mike
Forgot to mentionned the version. This is problematic with Qcubed 2.0.2
After digging deeper into this problem, I found that the problem may resid ein the POST data.
Looking at POST when a server action happen, I get results like this :
Array(
[c1] => on
[Qform__FormState] => 35
[Qform__FormId] => AdminForm
[Qform__FormControl] => c2
[Qform__FormEvent] => QClickEvent
[Qform__FormParameter] =>
[Qform__FormCallType] => Server
[Qform__FormUpdates] =>
[Qform__FormCheckableControls] => c1
)
Regardless of the value selected, c1 is always set to "On"
However, when I look at the POST data on an Ajax Action, the POST look like this :
Array(
[c1] => 0
[Qform__FormState] => 36
[Qform__FormId] => AdminForm
[Qform__FormControl] => c3
[Qform__FormEvent] => QClickEvent
[Qform__FormParameter] =>
[Qform__FormCallType] => Ajax
[Qform__FormUpdates] =>
[Qform__FormCheckableControls] => c1
)
the value of c1 is the actual selected Index of the QRadioButtonList.
It seems to me that the issue might reside somewhere in qcubed.js. I'm not familiar enough with javascript though to actually got further.
I just tried your code with "2.0 head" and I could not reproduce this behaviour.
Hi I figured out after comparing 2.0 branch to 2.0.2 Tag that the issue was already fixed.
You can refer to this ticket :
http://trac.qcu.be/projects/qcubed/ticket/671
Since this was fixed after the release of 2.0.2, you have to get the fix manually yourself.
The revision is :
http://trac.qcu.be/projects/qcubed/changeset/1040
Hope this help.
Mike