Change the drop-down list, showing or hiding columns based on values ​​of previous columns

QuestionsChange the drop-down list, showing or hiding columns based on values ​​of previous columns
Massimo Gagliardi asked 10 years ago

I have a problem with a dependant dropdown.

This is the relevant part of my code:

$col = array();
$col["title"] = $GLOBALS['form']['customer'];
$col["name"] = "IDClienteFornitore";
$col["dbname"] = "hmr_own_clienti_fornitori.RagioneSociale";
$col["width"] = "30";
$col["hidden"] = false;
$col["align"] = "left";
$col["editable"] = true;
$col["edittype"] = "select";
$str = $g->get_dropdown_values("SELECT DISTINCT IDClienteFornitore AS k, RagioneSociale AS v FROM hmr_own_clienti_fornitori WHERE FlagCliente ORDER BY RagioneSociale");
$col["editoptions"] = array("value"=>$str,
"onchange" => array("sql"=>"SELECT DISTINCT IDSottocliente AS k, RagioneSociale AS v FROM hmr_own_sottoclienti WHERE IDClienteFornitore = {IDClienteFornitore} ORDER BY RagioneSociale",
"update_field" => "IDSottocliente")
);
$cols[] = $col;

$col = array();
$col["title"] = $GLOBALS['form']['subcustomer'];
$col["name"] = "IDSottocliente";
$col["dbname"] = "hmr_own_sottoclienti.RagioneSociale";
$col["width"] = "30";
$col["hidden"] = false;
$col["align"] = "left";
$col["editable"] = true;
$col["edittype"] = "select";
$str = $g->get_dropdown_values("SELECT DISTINCT IDSottocliente AS k, RagioneSociale AS v FROM hmr_own_sottoclienti ORDER BY RagioneSociale");
$col["editoptions"] = array("value"=>":;".$str);
$cols[] = $col;

When you open the edit dialog from a customer who has a subcustomer you can see the drop-down list subcustomer populated with a blank line and all the subcustomers available (to change, if needed, the subcustomer) and selected the correct subcustomer, but when you select a customer without any subcustomer the drop-down list should be empty (or, better, hidden) and yet still shows all subcustomers with the only difference that appears selected the blank line;
Does anybody know a solution to this problem ?

Thank you in advance

Best regards

8 Answers
Abu Ghufran answered 10 years ago

Hello,

This should show empty dropdown. You may need latest build if not working in this way.
Kindly email me at [email protected] from your payment email address for updated lib.

Abu Ghufran answered 10 years ago

Hello,

Please email me grid code and sample database (sql).
I'll regenerate case and update you.

You can email at [email protected]

Massimo Gagliardi answered 10 years ago

I updated lib but the result didn't change.
Suggestions?
Thanks

Massimo Gagliardi answered 10 years ago

If I change the client in the dialog Add / Edit then the subcustomer drop-down list is shown only if the customer has or not subcustomers but if I edit a row with a customer who has not subcustomers then the edit window is opened showing a drop-down list with the subcustomers; if I select another customer and then go back to select the initial customer (the one without subcustomers) then, and only then, the drop-down list is shown empty.
What to do?
Suggestions?

Massimo Gagliardi answered 10 years ago

Thanks Abu for your solution that however is partial.
In the previous version you don't have a possibility to hiding the subcustomer in the case that the customer haven't subcustomers because the edit dialog shows however the subcustomers.
But, always in the previous situation, if the customer has the subcustomers you can view a drop down list with the subcustomer and with the blank choise –> $col["editoptions"] = array("value"=>":;".$str); <–.
Now this possibility isn't no more
Furthermore the add dialog, if you don't select any row, shows the error message "500: internal server error. Status: error".
Also in the add dialog if you choose the customer with subcustomers you cannot select a blank choise, because isn't shown

Massimo Gagliardi

Abu Ghufran answered 10 years ago

I've emailed an update that will add blank option in dropdown, with onload sql query.

Massimo Gagliardi answered 10 years ago

Hi Abu
The last solution is worse than the previous one.
Summary:
A customer (eg "East Trading") hasn't sub-customers and can't have them because in database table ("clienti_fornitori") the customer is set up with sub-customer ("GestioneSottoclienti")=false.
Therefore in the add/edit dialog of the "product lines" grid the drop-down list of sub-customers should not be there.
Instead another customer (for example "Bramac") can have sub-customers because in database table the customer is set up with sub-customer=true.
And in reality the cited customer has a sub-customer ("Bramac" in the database table "sottoclienti").
In this case in the "product lines" grid you can choose a new "product line" (or modify an existing one) to a sub-customer of the customer or directly to the customer.
Consequently the add/edit dialog must show the drop-down list of sub-customers with the sub-customer active (and in this case also showing the empty choise) or directly the blank choise, if the "product line" is directly for the customer.
I hope that it's all clear.

Warning: if you choose to add a new "product line" and no row is selected the script displays an error: "500 : Internal Server Error: Status: error"
Thanks

Massimo Gagliardi

Abu Ghufran answered 10 years ago

Changes:

1) Made 'GestioneSottoclienti' editable and hidden (so it is present on form for checking)

2) ​After show form, check if that field has 1 or 0, and hide subcustomer on that basis.

$grid["edit_options"]["afterShowForm"] = "function(form){ if (jQuery('#GestioneSottoclienti',form).val() == 0) jQuery('#tr_IDSottocliente',form).hide(); else jQuery('#tr_IDSottocliente',form).show() }";

3) Removed blank option from select.

I've emailed you changed files.

Your Answer

2 + 20 =

Login with your Social Id:

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 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

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

Let us improve this post!

Tell us how we can improve this post?