Dependent dropdown issue

I have an issue with dependent dropdowns in a form, have followed @ben dependent dropdown video

Everything works fine unless an aircraft make has no models loaded.
Each aircraft make can have 0, 1 or many aircraft models

I have 2 dropdowns:
1st is an aircraft make dropdown, with a datasource that provides an unfiltered list from aircraft make table
2nd is an aircraft model dropdown, with a datasource that provides a filtered list from aircraft model table based on aircraft makeID as the filter criteria from 1st dropdown.

Attached is video showing the results, you'll notice "Cessna" has no models loaded hence 2nd dropdown is blank, however when you select "Cessna" after having selected a make with models then "Cessna" will display that previous data, even though the query returned from backend has no data.

Note: Cessna is just an example, other makes without models have the same behavior.

I think this maybe a bug as I followed @ben tutorial, and don't believe I have done anything different, but am happy to be corrected.

Am on Wappler 6.5.2 Stable channel

Can you paste here:

  1. the code of the 2 dropdown selects
  2. a screenshot of the server action of the datasource for the 2nd dropdown (that fetches the models based on the 1st dropdown).

The 2nd is for making sure that you fetch the correct results (are there any relults?)

<select id="selAcaf_Make" class="form-select mb-5" name="selAcaf_Make" dmx-bind:options="scnAcaf_ModelFiltered.data.qryGetAcMake" optiontext="ac_make" optionvalue="ac_make_id"> <option value="">Select a Make</option> </select>

<select id="selAcaf_Model" class="form-select" name="selAcaf_Model" dmx-bind:options="scnAcaf_ModelFiltered.data.qryGetAcModelFiltered" optiontext="ac_model" optionvalue="ac_model_id"> <option value="">Select a Model</option> </select>

image



image

The filtered query results qryGetAcModelFiltered are showing no results as in my screenshot, and when there are models this same query shows results, and all is good as in model dropdown shows correct data

Can you please try 2 things:

  1. disable the auto run on your scnAcaf_ModelFiltered serverconnect
    image
    and fire it on the update event of the first dropdown (make) you have to fire again the scnAcaf_ModelFiltered and pass the current form selAcaf_Make.value

  2. add the .toNumber() formatter in your query condition

**I suggest use a DataView component to fetch the serverconnect’s data and filter that…

I have tried your suggestion and get the same results as my original way, problem still there.
Had to change it a little as the dropdown update event doesn’t fire as it has no data to select on page refresh, so I added a button to prime it, which worked.

From the way I see it the dropdown is working perfectly when there is data in the database model table, and when there is isn’t you can clearly see that the filtered query returns no data as expected. For some reason this empty query result is not updating the model dropdown?

I did it this way following @ben video as it was the only way I could see, but really like your suggestion of using dataviews as I can now see how that would work and will try it.

Having said that, the way I am doing it should work and doesn’t so would be good to get someone to confirm if this is indeed a bug or something I am doing wrong?

One last test…

After the column with the form (2 selects), add a new column (col-12)
image

Inside that column add a table based on the filtered models


image

So when you select the Make you will see what the filtered query results are…
Will they be the correct results?

1 Like

Good idea, video attached of the results.
You can clearly see that the dropdown is out of sync with the bootstrap table for aircraft makes that do not have a model in the child table

Hi Marc,

I suggest making these changes to how the server actions, server connects and select inputs have been setup.

  1. Setup two separate Server Actions and Server Connects for Makes and Models.
  2. Add variable filter in the Models Server Action.
  3. The binding for select statement for Makes is correct if you keep the same Server Action and Server Connect. Add an On Update Event in the select -> load the Models Server Connect -> assign value of the select input to the filter variable. This will now load the Models Server Action after filtering the data by ac_make_id.
  4. In the Models Select input, add binding with the new Server Action for models only and test.
2 Likes

It’s clear that the results on select are not correct loaded from the query…

But if it was my project I would do a last test before be sure it is a bug:
Add an onUpdate dynamic event on selAcaf_Model to load the serverconnect with filter parameter = selAcaf_Make.value and add a Deounce of 50ms

I had originally started with 2 separate server actions and 2 separate server connects, and went down this path before where I also thought it was a timing issue. So I put a button on the page and on its click event I would load the filtered server connect that populates the model dropdown.

So I would select a make from the dropdown that had linked models
Next I would select make “Cessna” that has no models
I would then click my button to force the model server action to reload with filtered data

This essentially eliminates timing issue altogether, and didn’t help my issue

Further more @famousmag idea of the bootstrap table proves that I don’t have a timing issue as both the model dropdown and bootstrap table have the same datasource, and yet they are out of sync for makes without related model records.

Since I am seeing the 2 separate query results in Chrome dev tools and the filtered query is empty on selecting the make of eg: “Cessna” I am convinced that the server connect is returning correct data i.e. the filtered server connect is returning an empty query results to the client

The model dropdown is not clearing its data when the input dataset is nothing, that is the main issue from what I can see.

If you disagree with my logic then let me know and I’ll try it 1 more time

Thank you @guptast, and @famousmag for your valuable input

@famousmag, ok, I have tried this way with debounce and no changes, fault remains

@famousmag, I have just tried with 2x dataview as suggested a better way by, and agreed I like it, but it has the same issue, fault remains

@guptast, I have tried your suggestion of 2 separate server actions, and end up with same issue

Really need Wappler team to confirm on their return from short break

I can confirm it to be a bug (v6.5.4).

The second Select Input, dependent on the first Select Input, doesn’t trigger an update when the underlying query returns an empty array. Additionally, the second Select Input persists values from the last known returned array values.

Table in the screenshots is showing expected values in the second dependent Select Input when the 1st Select Input values are changed.

  1. Screenshot showing the second Select Input correctly when the dependent query returns a set of values.

  1. Screenshot showing the second Select Input persisting with the last set of values when the dependent query returns empty array.

3 Likes

Could you test if the following update fixes the issue.

dmxAppConnect.zip (117.1 KB)

Hi Patrick, I have tested the updated AppConnect, and it has resolved the issue. Thank you for releasing the update.

Thank you Patrick for the fix

Fixed in Wappler 6.5.5

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.