Dropdown dependent

QuestionsDropdown dependent
Alberto asked 8 years ago

Hi,

I have two tables:

Users (id, name)
TypeOfTask (id, iduser, nametask)

In dropdown A, I've the list of users.
In dropdown B, I want to show the tasks of the user that is selected in first dropdown.

The code:
https://pastebin.com/embed_js/d2Rt9ZT9

Adding a record, It works fine, when a user is selected, the dropdown B shows his tasks, but when I'm modifiying a register, dropdown B shows all the tasks.

Adding:
http://prntscr.com/euxgvp

Modifying:
http://prntscr.com/euxho1

7 Answers
Abu Ghufran answered 8 years ago

Your code seems fine.Just swap these lines.
$col["editoptions"]["onload"]["sql"]="select tt_id as k, tt_descripcion as v from tipotareas where tt_idusuario='{t_idusuario}'";
$col["editoptions"] = array("value"=>":;".$str);
to
$col["editoptions"] = array("value"=>":;".$str);
$col["editoptions"]["onload"]["sql"]="select tt_id as k, tt_descripcion as v from tipotareas where tt_idusuario='{t_idusuario}'";

This line $col["editoptions"] = array("value"=>":;".$str); is basically resetting other line:

Alberto answered 8 years ago

Hi!

It fails when two users have a task with the same name. Example:

User 1 have a type of task Description=Administration with IdTypeTask=4
User 2 have a type of task Description=Administration with IdTypeTask=25

If I modify an Administration Task of User 2, in the second dropdown "Administration" is not selected.

If I modify an Administration Task of User 1, in the second dropdown Administration it's selected correctly.

It seems like with two or more TypeTasks having the same description it works fine with the typetask with lower IdTypeTask (in this case 4).

If I change description of IdTypeTask=25 to "Administration2" it works fine for the two users.

Thanks

Abu Ghufran answered 8 years ago

Hi,

Did the last solution helped? swapping lines for editoptions array,

$col["editoptions"] = array("value"=>":;".$str);
$col["editoptions"]["onload"]["sql"]="select tt_id as k, tt_descripcion as v from tipotareas where tt_idusuario='{t_idusuario}'";

Defining array first and then set onload-sql.

If issue still persist, you can send me complete code and database sql testing-dump at [email protected]

Alberto answered 8 years ago

Hi!

I've send you an email with code and database. When two users have a task with the same name/description:

TASK_ID: 40
USER_ID: 16
DESCRIPTIONTASK: ADMINISTRACION

TASK_ID: 59
USER_ID: 18
DESCRIPTIONTASK: ADMINISTRACION

If I edit a task of type ADMINISTRACION of user 16 it works fine, but if I modify a task of type ADMINISTRACION of user 18 the dropdown don't select it. Changing descriptiontask of TASK_ID 59 to "ADMINISTRATION2", it works fine.

Thanks

Abu Ghufran answered 8 years ago

Hello,

This ticket somehow remained unanswered.
Apologies for that.

We investigated this issue and currently it works this way.
The dropdown key / values must be unique in order to select properly. If same text have 2 ids, then it may perform unexpected.

Alberto answered 7 years ago

Hi, Abu

Is there anything new on this question?

Thanks

Abu Ghufran answered 7 years ago

Hello,

Currrently, it is not doable. Currently, we re-select dropdown value based on text label not id, and change is little complex.
I'd recommend a little rename one value to differentiate. It will then select as expected.

Your Answer

3 + 14 =

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?