Cascading dropdown with multiple choice?

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
graham
Veteran Member
Posts: 84
Joined: 2020-09-29 12:30

Cascading dropdown with multiple choice?

Post by graham » 2021-06-09 14:34

Hi. The 'tags' idea (https://bigprof.com/blog/appgini/a-work ... gini-apps/) works - I can add multiple choice options as described. And the cascading drop down works (https://www.youtube.com/watch?v=ySABQLupBRs) - the contents of the second drop down depend on the choice made in the first dropdown. BUT I want to somehow combine the two so that the result is a multiple-choice input field where the multiple choice options depends on the content of the previous drop down. I can get everything to work without error except the second box is still a dropdown that allows me choose just one option. In summary, I need to have multi-choice options that are relevant to the previous dropdown. Any thoughts appreciated. (It seems I can have one or the other but not both?) Thanks.

graham
Veteran Member
Posts: 84
Joined: 2020-09-29 12:30

Re: Cascading dropdown with multiple choice?

Post by graham » 2021-06-11 09:47

An alternatve explanation of the problem ... I have 3 tables: 'MOVIES'; 'GENRES' and 'SUB_GENRES'. 'GENRES' is just id and name; 'SUB_GENRES' is 'ID', 'parent genre' (looks up 'genres') and 'name'. 'MOVIES' has a field 'genre' which is a look up field linked to 'GENRES.name' and a field 'sub_genres' which looks up GENRES.name and has the 'filter by genre' box ticked. So when I add a movie, I get a drop down list of genres in MOVIE.genre, and a drop down of the sub-genres connected to the genre. But I can only add one sub-genre when there might be 2 or 3 that are applicable. For example, Film A - genre: comedy; sub-genre: family, slapstick.
I could simply have movies.sub_genre1, movies.sub_genre2, movies.sub_genre3 but I'd prefer a more eloquent solution.
And because I followed the 'A work-around to implement a multiple choice lookup field (https://bigprof.com/blog/appgini/a-work ... gini-apps/) I also have the following in hooks/sub_genres.php
function update_sub_genres_list() {
// retrieve existing sub_genres
$sub_genres = array();
$res = sql("select * from sub_genres order by name", $eo);
while($row = db_fetch_assoc($res))
$sub_genres[] = $row['name'];

// save the sub_genres to the options list file
$list_file = dirname(__FILE__) . '/sub_genres.name.csv';
@file_put_contents($list_file, implode(';;', $sub_genres));
}
and update_sub_genres_list(); after insert, update and delete in this doc as per url guide. And also in hooks - sub_genres.name.csv
So that's it - the sub-genre list appears correctly in MOVIES - but I can only choose one option when I need to choose 2/3.

Post Reply