Dependent Dropdown Issue

QuestionsDependent Dropdown Issue
Alfonso Cabrera asked 3 years ago

Hi Abu!

I have a problem with a dependent dropdown, below is the code I use to generate inside the grid the 2 components. Whenever I edit a record it doesn't show the selected option of the 2nd dropdown. It is strange because when you see the record before you edit it, you see the dropdown with the selected option but not when you edit the record.

Below is the code of the 2 dropdown's.

$col = array();
$col["title"] = "Cliente"; // caption of column
$col["name"] = "idClientes"; // grid column name, must be exactly same as returned column-name from sql (tablefield or field-alias)
$col["editable"] = true;
$col["width"] = 200;
$col["edittype"] = "select"; // render as select
$str = $g->get_dropdown_values("SELECT idClientes as k, nombre as v FROM clientes ORDER BY nombre");
$col["editoptions"] = array(
"value" => $str,
"onchange" => array("sql"=>"SELECT idUnidad_Medica as k, nombre as v FROM unidad_medica WHERE idClientes = {idClientes} ORDER BY nombre",
"update_field" => "idUnidad_Medica")
);
$col["formatter"] = "select"; // display label, not value
$cols[] = $col;

$col = array();
$col["title"] = "Unidad<br>Médica"; // caption of column
$col["name"] = "idUnidad_Medica"; // grid column name, must be exactly same as returned column-name from sql (tablefield or field-alias)
$col["editable"] = true;
$col["width"] = 200;
$col["edittype"] = "select"; // render as select
$str = $g->get_dropdown_values("SELECT idUnidad_Medica as k, nombre as v FROM unidad_medica ORDER BY idUnidad_Medica");
$col["editoptions"] = array("value" => $str);
// initially load 'note' of that client_id
$col["editoptions"]["onload"]["sql"] = "SELECT idUnidad_Medica as k, nombre as v FROM unidad_medica WHERE idClientes = {idClientes} ORDER BY nombre";
$col["formatter"] = "select"; // display label, not value
$cols[] = $col;

2 Answers
Abu Ghufran answered 3 years ago

In newer build, the change event of parent dropdown is invoked, which tries to load dependent dropdown itself.
Now child dropdown does not need to a onload-sql option. You can try removing this line:

$col["editoptions"]["onload"]["sql"] = "SELECT idUnidad_Medica as k, nombre as v FROM unidad_medica WHERE idClientes = {idClientes} ORDER BY nombre";

It should work normal after that.

Alfonso Cabrera answered 3 years ago

Hi Abu!

Here is a link to a video that will show you that when ever I edit a grid with 2 dropdowns, you can see that one of them doesn't show the corresponding item.

https://drive.google.com/file/d/0B8edCSfz6ypgSDhoSkozb1dqVkU/view?usp=sharing

Your Answer

1 + 15 =

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating / 5. Vote count:

As you found this post useful...

Follow us on social media!

We are sorry that this post was not useful for you!

Let us improve this post!