Ticket #422 (closed defect: invalid)
Callback problem
| Reported by: | eirik.hoem@… | Owned by: | wei |
|---|---|---|---|
| Priority: | urgent | Milestone: | 3.1 Alpha |
| Component: | Prado Framework v3 | Version: | 3.1 |
| Severity: | major | Keywords: | |
| Cc: |
Description
Callbacks sometimes update stuff they are not supposed to do. In this case I've modified the ActiveDropDownList? test from trunk to reproduce the problem. It's two dropdown lists, where a selection in the first list determines which items should be selected in the other. First time you select something in list two it works fine, but the next time the callback seems to mess it up.
Further info: http://www.pradosoft.com/forum/index.php/topic,5873.0.html
Possibly related topic: http://www.pradosoft.com/forum/index.php/topic,5853.0.html
Home.page
<com:TContent ID="Body"> <com:TActiveDropDownList ID="list1" AutoPostBack="true" OnSelectedIndexChanged="list1_changed"/> <com:TActiveDropDownList ID="list2" Enabled="false" AutoPostBack="true" OnSelectedIndexChanged="list2_changed" /> <div style="margin:1em; padding:1em; border:1px solid #ccc; text-align:center;"> <com:TActiveLabel ID="label1" Text="Label 1" /> </div> <div style="margin:1em; padding:0.5em; text-align:center; border:1px solid #ccc;"> <com:TActiveButton ID="button1" Text="Select Index 3" OnClick="select_index_3" /> <com:TActiveButton ID="button2" Text="Clear selection" OnClick="clear_selections" /> <com:TActiveButton ID="button3" Text="Select Value 'value 2'" OnClick="select_value_2" /> <com:TActiveButton ID="button4" Text="Select Item 3 And Sub Item 3" OnClick="select_index_3_plus" /> </div> <com:TJavascriptLogger /> </com:TContent>
Home.php
<?php
class Home extends FPage{
private $_listItemsA;
private $_listItemsB;
public function onInit($param){
parent::onInit($param);
$this->_listItemsA[] = array("title" => "Please select", "id" => -1,"category" => -1);
$this->_listItemsA[] = array("title" => "Item A", "id" => 1,"category" => 1);
$this->_listItemsA[] = array("title" => "Item B", "id" => 2,"category" => 1);
$this->_listItemsA[] = array("title" => "Item C", "id" => 3,"category" => 1);
$this->_listItemsA[] = array("title" => "Item D", "id" => 4,"category" => 1);
$this->_listItemsA[] = array("title" => "Item E", "id" => 5,"category" => 1);
$this->_listItemsB[] = array("title" => "List 2 Item A", "id" => 1,"category" => 1);
$this->_listItemsB[] = array("title" => "List 2 Item B", "id" => 2,"category" => 1);
$this->_listItemsB[] = array("title" => "List 2 Item C", "id" => 3,"category" => 1);
$this->_listItemsB[] = array("title" => "List 2 Item D", "id" => 4,"category" => 2);
$this->_listItemsB[] = array("title" => "List 2 Item E", "id" => 5,"category" => 2);
$this->_listItemsB[] = array("title" => "List 2 Item F", "id" => 6,"category" => 2);
$this->_listItemsB[] = array("title" => "List 2 Item G", "id" => 7,"category" => 3);
$this->_listItemsB[] = array("title" => "List 2 Item H", "id" => 8,"category" => 3);
$this->_listItemsB[] = array("title" => "List 2 Item I", "id" => 9,"category" => 3);
$this->_listItemsB[] = array("title" => "List 2 Item J", "id" => 10,"category" => 4);
$this->_listItemsB[] = array("title" => "List 2 Item K", "id" => 11,"category" => 4);
$this->_listItemsB[] = array("title" => "List 2 Item L", "id" => 12,"category" => 4);
$this->list1->DataValueField ='id';
$this->list1->DataTextField = 'title';
}
public function onLoad($param){
parent::onLoad($param);
$this->list1->DataSource = $this->_listItemsA;
$this->list1->dataBind();
}
function list1_changed($sender)
{
if ($sender->getSelectedValue() == -1){
$this->label1->setText("Please select a category");
$this->list2->setEnabled(false);
return;
}
$this->addOptionsToListProblem($sender->getSelectedValue());
}
function addOptionsToListProblem($parent)
{
$foo = array();
$bar = 0;
$sel = array("title" => "Please select", "id" => -1,"category" => -1);
$foo[] = $sel;
foreach ($this->_listItemsB as $p){
if ($p["category"] == $parent){
$foo[] = $p;
}
}
$this->list2->DataValueField = 'id';
$this->list2->DataTextField = 'title';
$this->list2->DataSource = $foo;
$this->list2->dataBind();
$this->list2->setEnabled(true);
}
function list2_changed($sender)
{
$this->label1->setText("Selection 2: ".$sender->getSelectedValue());
}
function select_index_3()
{
$this->list1->setSelectedIndex(3);
}
function clear_selections()
{
$this->list1->clearSelection();
}
function select_value_2()
{
$this->list1->setSelectedValue("value 2");
}
function select_index_3_plus()
{
$this->list1->setSelectedValue("value 3");
$this->list1_changed($this->list1);
$this->list2->setSelectedValue("value 3 - item 3");
}
}
?>
JS Log
List 1 select item:
HTTP 200 with response : Actions :
{"Prado.Element.select":["ctl0_Body_list1", "selectClear", null, 6]}
{"Prado.Element.select":["ctl0_Body_list1", "selectIndex", 1, 6]}
{"Prado.Element.setOptions":["ctl0_Body_list2", [["Please select", "-1"], ["List 2 Item A", "1"], ["List 2 Item B", "2"], ["List 2 Item C", "3"]]]}
{"Prado.Element.setAttribute":["ctl0_Body_list2", "disabled", false]}
List 2 select item first time:
HTTP 200 with response : Actions :
{"Prado.Element.replace":["ctl0_Body_label1", "Element.update", "Selection 2: 1", null]}
List 2 select item second time:
HTTP 200 with response : Actions :
{"Prado.Element.select":["ctl0_Body_list1", "selectClear", null, 6]}
{"Prado.Element.select":["ctl0_Body_list1", "selectIndex", 1, 6]}
{"Prado.Element.select":["ctl0_Body_list2", "selectClear", null, 4]}
{"Prado.Element.select":["ctl0_Body_list2", "selectIndex", 2, 4]}
{"Prado.Element.replace":["ctl0_Body_label1", "Element.update", "Selection 2: 2", null]}
{"Prado.Element.setOptions":["ctl0_Body_list2", [["Please select", "-1"], ["List 2 Item A", "1"], ["List 2 Item B", "2"], ["List 2 Item C", "3"]]]}
Change History
Note: See
TracTickets for help on using
tickets.
