Forums

Dynamic Dropdown

RamboRon 19 Sep, 2015
I have read this topic and it works great.

https://www.chronoengine.com/faqs/70-cfv5/5232-how-do-i-build-a-dynamic-drop-down-in-cfv5.html

The problem I am having is in adding a third dropdown populated by the choices of the first and second dropdown. The first Db Read puts data in the model 'depart' and this data fills the first dropdown. That starts the 'ajax' event DB Read that is save under model 'Data' and this populates the second dropdown. This then triggers the 'ajax2' event and the DB Read saves in the model 'Data2' to fill the third dropdown. But the third dropdown never propagates. I suspect the DB Read condition.

Below is my condition statement for Data2 model:

<?php
return array( 'Dept' => $form->data['depart.dept'], 'Class' => $form->data['Data.class'], );
?>

I know I have something wrong just can't see it. I have tried several different ways but can't get the AND to work. Please help! I will buy you 5 coffees, maybe 10 if I feel stupid enough. Thanks in advance for your help.
GreyHead 20 Sep, 2015
Hi RamboRon,

I think that the problem with your Condition statement is two-fold.

a) The syntax is $form->data['Data']['class'] and not ['Data.class']; and also you may only need $form->data['class'] here.

b) I don't think that $form->data['depart']['dept'] is available to the event, its not passed as a parameter in the Ajax URL. Do you need it or can it be looked up from the 'class' ?

Bob
RamboRon 20 Sep, 2015
Boy do I feel dumb, but that good for your coffee fund.

I thought I had read model.data from PHP site, but I'm not very good so obviously I misunderstood.

The problem is the depart pulls out of a different database. Could I add a second DB Read to ajax2? But then how do I write the join in PHP?
GreyHead 21 Sep, 2015
Hi RamboRon,

I checked the code yesterday and it looks as though the Ajax call sends all the current form data when it it made - so that should include the previous selection. Try using $form->data['dept'] and see if that works,

Bob

PS You can debug Ajax calls using your browser web developer tools. I use Chrome and, on the Network tab I can see what has been sent back to the server and what is returned. If necessary you can add debug code to the Ajax event and it will be shown in the returned data - it may well also throw up a bunch of errors but that is OK, they will go away once you remove the debug code.
RamboRon 21 Sep, 2015
This will give me a few things to work on and see if I can get it. I don't see your buy me a coffee link. Are you not doing that anymore? Do you have a book for v5 yet and what is the cost? I'll let you know how it turns out.
RamboRon 22 Sep, 2015
I tried $form->data['dept'] first before I tried $form->data['depart.dept']. Also $form->data['depart']['dept'] did not work either. I will add some debug code and get back to you. I did find your link and send you some coffee. Boy do I feel dumb there.
RamboRon 22 Sep, 2015
I must be really stupid but an AND condition should return nothing if both conditions are not met.
 <?php
return array( 'Dept' => $form->data['dept'], 'Class' => $form->data['class'], );
  ?>

How is this call only returning class 1 as displayed in the captures I sent below?
RamboRon 01 Oct, 2015
I have tried adding
echo form->data['depart'][DeptID];
echo form->data['depart'][Description];

but it breaks the ajax at that point and never reports back the variable.

Can the Non-Profit hire you to help with this problem?
This topic is locked and no more replies can be posted.