User of edit fields in my dropdown SELECT

QuestionsUser of edit fields in my dropdown SELECT
Lynn Lollar asked 4 years ago

All,

How can I use the value from another field in an edit to be in my drop down SELECT.

$str = $g->get_dropdown_values("SELECT id as k, game_name as v FROM games
JOIN users_qual_pos ON games.id = users_qual_pos.pos_id
WHERE users_qual_pos.staff_id='5'");

I need the staff_id to be whats in another column. Not 5. Using the 5 does work so I feel that the value is not being set correctly. I tried changing the '5' to '{staff_id}'.

Thank you so much for the help.

5 Answers
Abu Ghufran answered 4 years ago

You can have it using onload-sql option.

// set editoption values without condition
$str = $g->get_dropdown_values("select note as k, note as v from invheader");
$col["editoptions"] = array("value"=>$str);

// then … initially load 'note' of that client_id
$col["editoptions"]["onload"]["sql"] = "select note as k, note as v from invheader WHERE client_id = '{client_id}'";

Refer demos/appear/dropdown-dependent.php

Lynn Lollar answered 4 years ago

I still can't get this to work. The example show an "onchange" funtion.

The {staff_id} is still not being poplulated. The only way I can get this to work is putting the staff_id number 5 there. How can I get more help on this?

Thanks.

The grid works as I hoped as long as I hard code the staff id.

Abu Ghufran answered 4 years ago

Please email me the complete grid code for review.
You can share pastebin.com link OR email me at [email protected]

E Mello answered 3 years ago

Hi Abu,

I have been having the same problem as above.
How did you solve the problem?

My issue explained:

2 dropdowns: Address and Room location
The Room location dropdown is dependent of Address dropdown.
I have played loads with this.
If I hard code, it works.
If I don't have conditions on the get_dropdown_values (which your demo shows), it does not work.
If I place {property_id} in the get_dropdown_values query (the ideal scenario), the {property_id} does not get populated.

Code I have tried:
__________________________________________________________________
Address field:

$col = array();
$col["title"] = "Address";
$col["name"] = "property_id";
$col["show"] = array("list"=>false, "add"=>true, "edit"=>true, "view"=>false);
$col["editable"] = true;
$col["editrules"] = array("required"=>true);
$col["edittype"] = "select";
$str = $g->get_dropdown_values("SELECT address AS v, property_id AS k FROM property p WHERE active = 1 ORDER BY address");
//requires column property_id above
$col["editoptions"] = array(
"value"=>$str,
"onchange" => array("sql"=>"SELECT rl.description as v, r.room_id as k FROM room r
INNER JOIN room_location rl ON rl.room_location_id = r.room_location_id
WHERE r.property_id = '{property_id}' AND r.active = 1",
"update_field" => "room_location_description" ));
$cols[] = $col;

__________________________________________________________________
Room location field (HARD CODED):

$col = array();
$col["title"] = "Room location";
$col["name"] = "room_location_description";
$col["show"] = array("list"=>true, "add"=>true, "edit"=>true, "view"=>false);
$col["editable"] = true;
$col["edittype"] = "select";
//$str = $g->get_dropdown_values("SELECT room_id as v, room_id as k FROM room");

$str = $g->get_dropdown_values("SELECT rl.description as v, r.room_id as k FROM room r
INNER JOIN room_location rl ON rl.room_location_id = r.room_location_id
WHERE r.property_id = '22' AND r.active = 1");
$col["editoptions"] = array(
"value"=>$str,
"onload" => array("sql"=>"SELECT rl.description as v, r.room_id as k FROM room r
INNER JOIN room_location rl ON rl.room_location_id = r.room_location_id
WHERE r.property_id = '{property_id}' AND r.active = 1"));
$col["editrules"] = array("required"=>true);
$col["width"] = "75";
$col["align"] = "center";
$cols[] = $col;

__________________________________________________________________
Room location field using {property_id} – DOES NOT POPULATE {property_id}:

$col = array();
$col["title"] = "Room location";
$col["name"] = "room_location_description";
$col["show"] = array("list"=>true, "add"=>true, "edit"=>true, "view"=>false);
$col["editable"] = true;
$col["edittype"] = "select";
//$str = $g->get_dropdown_values("SELECT room_id as v, room_id as k FROM room");

$str = $g->get_dropdown_values("SELECT rl.description as v, r.room_id as k FROM room r
INNER JOIN room_location rl ON rl.room_location_id = r.room_location_id
WHERE r.property_id = '{property_id}' AND r.active = 1");
$col["editoptions"] = array(
"value"=>$str,
"onload" => array("sql"=>"SELECT rl.description as v, r.room_id as k FROM room r
INNER JOIN room_location rl ON rl.room_location_id = r.room_location_id
WHERE r.property_id = '{property_id}' AND r.active = 1"));
$col["editrules"] = array("required"=>true);
$col["width"] = "75";
$col["align"] = "center";
$cols[] = $col;

__________________________________________________________________
Room location field without conditions in the get_dropdown_values (WHICH YOU SUGGEST IN YOUR DEMO) – DOES NOT WORK

$col = array();
$col["title"] = "Room location";
$col["name"] = "room_location_description";
$col["show"] = array("list"=>true, "add"=>true, "edit"=>true, "view"=>false);
$col["editable"] = true;
$col["edittype"] = "select";
//$str = $g->get_dropdown_values("SELECT room_id as v, room_id as k FROM room");

$str = $g->get_dropdown_values("SELECT rl.description as v, r.room_id as k FROM room r
INNER JOIN room_location rl ON rl.room_location_id = r.room_location_id");
$col["editoptions"] = array(
"value"=>$str,
"onload" => array("sql"=>"SELECT rl.description as v, r.room_id as k FROM room r
INNER JOIN room_location rl ON rl.room_location_id = r.room_location_id
WHERE r.property_id = '{property_id}' AND r.active = 1"));
$col["editrules"] = array("required"=>true);
$col["width"] = "75";
$col["align"] = "center";
$cols[] = $col;

Abu Ghufran answered 3 years ago

The last column settings should work by reviewing just code.
However, there could be other issues.

Please email me your full grid code and database sql dump (testing records) to regenerate case.

Your Answer

11 + 0 =

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!