Multiple choice response from multi-select cascading dropdown (a matrix question?)

chrisyork

Member
OK, so this is ambitious, I know...

I have a cascading dropdown [CDD] that is currently a checklist. It is derived from another checklist [dbjoin], and FANTASTICALLY it 'just works' (i.e. when I click an extra option on the first list, the CDD updates). Nice! This gives me a great way to 'drill down' and ask people to choose relevant sub-categories, rather than present a huge list to wade through.

To illustrate this is (sort of) what it looks like

dbjoin element
1 [selected]
2 [selected]
3 [selected]
4

CDD element (dynamic list)
1A
1B [selected]
1C
2D
2E [selected]
3F
3G
(not shown 4H, 4I, 4J)

However, what I'd really like to do is have a list generated like the CDD where the user can select (for example) small, medium, large (s/m/l) for each item.

So something like this

1A (s/m/l])
1B (s/m/l]) - [l selected]
1C (s/m/l])
2D (s/m/l])
2E (s/m/l]) - [m selected]
3F (s/m/l])
3G (s/m/l]) - [s selected]

So the 'response' stored is 1B-l, 2E-m and 3G-s (hope that makes sense)

I don't mind if this is a multistep process - so maybe first the CDD generates a list and subsequent element(s) / group(s) or form uses this list. But I'm not sure how to create the matrix, and it is possible that it is WAY too complicated for my little brain.

And because I can't predict how many selections are in my dbjoin [e.g. 1-3 above] or CCD (e.g. 1B, 2E, 3G above) I'm not sure whether Fabrik has an element plugin that would collect and display them without having all possible combinations from 1A to 4J as pre-configured elements (e.g. radio-buttons) and hiding them until they have been selected in the CDD element. I feel like there should be a more 'elegant' solution...

The bad news (for me) is that so far I have 15 choices in my dbjoin element and up to 95 choices in the CDD - so potentially 95 elements if I went down that cul-de-sac. And if any of those choices are edited in future (e.g. to change the name, or add an extra) I'm worried about having to manually edit or add extra elements....

Any thoughts or guidance greatly appreciated!
 
Hi there!

I'm not sure if your idea is feasible only by configuring the existing elements. I would try to custom-build a checkbox list using the PHP field in the Advanced tab. I use it to get structured list with sub-titles (optgroups), the entries are derived from another list. Here's the code:

Code:
$poptions = array();
$db =\Joomla\CMS\Factory::getContainer()->get('DatabaseDriver');
$db->setQuery('SELECT DISTINCT type FROM pathologies ORDER BY type ASC');
$rows = $db->loadObjectList();
foreach ($rows as $row) {
    $poptions[] = Joomla\CMS\HTML\Helpers\Select::option('optgroup', $row->type);
    $db->setQuery('SELECT pathology_disorder FROM pathologies WHERE type ="'.$row->type.'" ORDER BY pathology_disorder ASC');
    $patcs = $db->loadObjectList();
    if ($patcs) {
      foreach ($patcs as $patc) {
      $poptions[] = Joomla\CMS\HTML\Helpers\Select::option($patc->pathology_disorder, $patc->pathology_disorder);
      }
    }
}
return $poptions;

You could replace the first query with the choice from the first choice, and then using those to retrieve the "sub-choices" with the second query.

Kindly,
Lorenz
 
Hi Lorenz,
Thanks for your suggestion. Apologies for the delay in responding - busy on another project (I don't mean to appear as if I've ignored your help!)

I can't quite visualise what your structured list looks like because I'm not that good enough at 'decoding' and then translating it of what I think it might look like without seeing the values in any of the tables! That's my weakness not a deficiency in your suggestion, by the way.

Would it look something a bit like this? with 1A / 1B etc being the optgroups and the [ ] representing possible choices (apologies for the odd looking formatting!):

_1A
____ s [ ]
____ m [ ]
____ l [ ]
_1B
____ s [ ]
____ m [ ]
____ l [ ]

If so, that might be a solution - but I haven't been able to transcribe your code to my situation yet.

Appreciate the help.
 
Hello

Yes, the list would look like this. The user could only select s,m, or l under 1A or s, m, l under 1B. Ideally, you would need a separate list that defines how many sub-categories 1A, 1B, 1C ... have. Depending on the selection in your first field (1, 2, 3 ....) this code would then collect the details specifications for say 1 and 2 and show the list 1A (s,m,l), 1B (s,m), 2A (s,m,l) etc.

I am afraid, I cannot go much deeper without knowing your exact setup and the element and list names. But here's an encouragement: I don't really know much coding myself, I started by using the example that Fabrik provides and tweaking them wit the help of Google until the code did what I wanted it to do.

Kindly,
Lorenz
 
Hi Lorenz,
Thanks - that helps me. Actually it's not the solution I'm looking for - I would want to be able to select s/m/l in any or all group (so it would be a multi-select). But sometimes another perspective opens the brain a little, so you have done some good!

I think that what I need to do is use my existing form that allows cascading multi-select to get as far as 1A, 1B etc.
Then generate a filtered list to allow the user to open a separate form for each of the 1A options (so that I can provide enough information about their prospective choices) then 1B and for the user to be redirected to the list (which then filters out the answered choices (i.e. 1A drops off the list if there is a response to s/m/l). Obviously, I was just using s/m/l as a proxy to something more complicated ;-)

So you've given me the inspiration but not the answer, and I have the same Modus Operandi, but I call it 'A little knowledge is a dangerous thing' - because my curiosity gets me into all sorts of trouble! And then other kind souls like yourself and others on this forum (stand up and take a bow @troester) dig me out :) or at least give me a shovel to dig with.

Thanks for taking the time to share your experience and knowledge - I will try to remember to come back and explain what I've done, if I manage to get a working solution. I think I need to consider new list with table join to a repeat sub-table (the one from the second multi-select), which is probably going 'off-piste'...
 
I'm going round in circles and they are 'ever decreasing' trying to get a 'logical' solution.

Because of a problem with the multi-select cascading dropdown reset problem http://fabrikar.com/forums/index.php?threads/cascading-dropdown-reset-on-edit-feature-or-bug.54308/ I have had to try a different approach. NOTE - the cdd resets any time the controlling element is changed, whether in new or edit form. So that looks like a feature rather than a bug.

I have changed my form structure to a repeating group - so that there is a main record with just the rowid and userid

Then repeatable group for two elements, but with numbers now a radio, rather than check list - so that I can mimic multi-select for numbers, but use the repeat group for the 'logical structure'.

But it complicates things further, and not (in my head) consistently.

When you select from numbers the letters are populated in the first group.

When you add a new subgroup the letters element is already populated with the preceding number sub-options. Then it 'concatenates' the new number's sub-options when a new number is selected. It does not restrict the 'where clause' to this repeat-group. So it is behaving as if there is no repeat and I can't find a way to restrict the placeholder to the current repeat-row - pseudocode: {table___element_raw_#}

Confusing me because a calc element that refers to an element placeholder only picks up that repeat's element. So I can list the options as a calc for just that repeat, but can't do the same with a dbjoin.

I have also tried using a dropdown and populating that using the same query in advanced -> php eval (with a javascript trigger), but it comes back with Array to string conversion in line 449 of dropdown.php:

foreach ($rows as $row) { $options[] = JHTML::_('select.option', $row->id, $row->letter_name); } return $options;

I can't see why the code breaks - it is identical structure to the examples and many responses in the forum! I have declared $options = array(); and even tried a radiobutton with Joomla\CMS\HTML\Helpers\Select::option instead of JHTML::_ because I'm floundering now!

At every turn there is a small boulder tripping me up, yet I am trying really hard to check code, follow guidance etc.

For now I am going to have to regress to the calc to list letters, then have a second form that allows the user to go back through that list of letters (one form for each number previously selected - got that working) to select the relevant ones again using a repeat and a radio in each repeat to get me to the s/m/l.

Which is a bit of a poor experience for the user.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top