Problem with cascading dropdown checkbox displaying data

I have a problem with a cascading dropdown rendered as a checkbox failing to display data. From the list, if I edit a record, the form shows all data as expected except for the checkbox, which has the expected set of boxes, but all blank. If instead I view the record, the checkbox data all appears (albeit formatted as a concatenated string with no separators between the items). If I open the form directly (with an existing record specified) the data is missing as for access via the list. The data source for the list/form is a view and there is another view for the data source for the checkbox itself. (I am using views as I am creating a list/form to work with an existing complex database system.)

Normally, when something does not work, I assume I have made a mistake, but if I have here, why does it work when viewing, but not when editing? Can anyone please help?

(I am using Joomla! 3.9.22, Fabrik 3.9.2, PHP 7.3.24, MySQL 5.7.32.)
 
Editing and saving the data is not the problem (I use php onBeforeProcess for saving what I need to). The problem is that the checkbox does not show the existing data.
 
Thanks for taking an interest. OK, here goes.

I am developing a form which was working as far as it went. It has about 30 elements including a checkbox which I needed to change to a cascading dropdown rendered as checkboxes. I had a few problems doing this, partly because I had assumed that the cascading version would be similar to the ordinary one, whereas it is actually based on the database join, which requires an extra table to hold the data for the element. After much digging around in Fabrik, I sorted out the format needed and created a new view to provide the data for the element. At this point, to tidy up various bits of history, I created a new list and form based on a new view copied (and tidied) from the old one, together with another view for the CDD data. Fabrik created a new set of elements as fields, which I edited to the elements actually required, including the CDD checkbox. When the CDD checkbox was created, Fabrik seemed happy to use the view and did not create another table. Then I logged in to the front end of the form where the expected data appeared in the checkboxes. However, that is the only time it did appear; on subsequent logins, the checkboxes were empty. I tried editing the element back to a field and then back to a CDD checkbox, but the front end showed no data, even the first time.

Now, from the front end, I can access the list, choose any record and select either edit or view for it. Consistently, if I select view, the CDD data appears correctly, but if I select edit, the CDD checkboxes are all empty. I presume there must be some difference in the way Fabrik fetches the data in the two cases, but I have been unable so far to find where in the code it does this in order to investigate further.

I am sorry this is rather long winded, but thought it best to explain what I have done. Any ideas?!

John
 
So, you've created new Fabrik templates for list and form to make a CDD working -- although it isn't really a CDD element? If so, I guess then something went wrong along the way.

Similar to your initial post, you're saying, "the checkboxes were empty", "showed no data", "the CDD checkboxes are all empty". So, what's missing, the values (= the checks) or the labels or both?

Since it could become pretty laborious to dig deeper into your custom templates and code etc, I think you'd be better off if you kept the checkbox element as exactly that (not a "quasi-CDD"), the templates simpler and at least closer to the defaults, and used custom JS to mimic the conditional "CDD" behaviour as required.
 
I can’t have explained this very well. I have not created any new Fabrik templates; I am using a completely standard Fabrik CDD and, in “Details : Data : Render as”, selecting “Checkbox list”.

In the front end form display (selecting “Edit” from the list), the correct selection of boxes and labels appears (and the selection shown changes as expected when the watch element changes), but no checks appear in any of the boxes.

As far as I am aware, the standard CDD behaviour should be fine and no custom templates or JS should be needed for what I am doing. Selecting “View” from the list works fine now, showing all the expected data.

John
 
Ok, sorry if I didn't get it, but at least to me it is really confusing with views and all (and I'm still not sure I've got it all straight now, haha).

Well, so you're using MySQL views to "read" the data for list and details, correct?
And when submitting a form, you're using a PHP form plugin at onBeforeProcess to "write" = store the data in the non-Fabrik tables (from which the MySQL views are generated), correct?

So, where would the form then get data from for the CDD? I could be wrong because I haven't had such case yet, but to me it seems it's not where it expects it, or not in the required format?
Are you getting any (JS) errors?
Have you compared your setup with a "regular" Fabrik list incl a checkbox CDD and how data is handled and stored in the DB?
 
It is confusing – it confuses me and I have been dealing with it for a while!
Well, so you're using MySQL views to "read" the data for list and details, correct?

Yes.
And when submitting a form, you're using a PHP form plugin at onBeforeProcess to "write" = store the data in the non-Fabrik tables (from which the MySQL views are generated), correct?

Yes.

When I first added a checkbox CDD I found that Fabrik had created an additional table for the CDD data. I examined that and worked out (eventually and after a few false starts) what was needed from the view that I had to create to replace the added table. When I then created the new form based on the two new main and CDD data views, Fabrik did that without creating a new table for the CDD data, so I presume it was happy with the view I had created as the place to get the data from for the CDD. Since the correct CDD data is shown when I select “View” for a record in the list, surely Fabrik must be accessing my CDD data view and be happy with its format and contents to do that. There are no JS or other errors; the only error is the lack of checks in the boxes when I select “Edit” for a record in the list.

John
 
Well, with CDD checkboxes generally working in a "regular" Fabrik setup, I dare saying it's pretty obvious that something is fishy in your particular configuration. This may be related to the MySQL views or custom code or else, but obviously it's hard to impossible to point at a specific "thing" from the distance.

This
If instead I view the record, the checkbox data all appears (albeit formatted as a concatenated string with no separators between the items).
also indicates that something is wrong with the views or the data in them, wouldn't you agree?

So, I guess you'll need to go through your entire setup step by step again, if your way is the one you want to keep going.

There may be an alternative way, e.g. by building Fabrik "helper" lists from scratch, in its own tables basically holding the same data as that other "existing complex database system" you mentioned, and keeping them in sync with PHP plugins. No involvement of MySQL views, no trouble from attempting to build something outside of Fabrik which, in the end, it still won't fully work with due to whatever culprit.
 
As you say, I suspect that something somewhere is not quite right. I do not think it practical to keep a system of over 70 linked tables synchronised with a separate set maintained by Fabrik, so if I want to have this feature I will need to find the problem. At an earlier stage, I found a problem elsewhere by digging into what the Fabrik code was doing. In that case, debug showed a PHP error and with the accompanying stack trace I was able to find where Fabrik was creating an SQL query. Examining the query it produced, I was able to find what I needed to change in my code to correct the problem.

I suspect it might be possible to do something similar in this case, but with no actual error appearing, I do not know where to look. I have examined the Fabrik code to try and find where it fetches the data, but without success. As you say, the concatenation with no separators indicates that something is wrong. Do you have any idea where in the Fabrik code fetching and processing the data is done? Alternatively, do you have any idea where I might be able to find out? Presumably someone somewhere must know.

John
 
70 tables?! That -- times X columns -- is what this form including the CDD caters to?! Somehow I have trouble believing this, haha.

Anyway... yeah, your best chance is probably turning on debug in Fabrik options, appending &fabrikdebug=1 to the URL, then studying the queries.
 
Thanks for this.

By the way, I do not have one form dealing with 70 tables! I have many forms for various parts of the system; that is why I need views that pull together the parts of the system needed for each form.

I already had Fabrik debug on, but had missed the need to append &fabrikdebug=1; it can be difficult to find clear information on how to do some things with Fabrik. I now have a vast amount of debug information to try and make sense of, but have already noticed by expanding the “form:data” section that the data for my CDD field has correct entries for “..._raw” and “..._id”, but the actual text entries are duplicated, which seems wrong.

For sorting this out, it would be helpful to have some guidance on what the various sections in the debug are and how they relate to the Fabrik code. Do you know anywhere I might be able to find any information to help?

John
 
You may try the search in the Wiki (I've done that for you here: https://fabrikar.com/forums/index.php?search/30278581/&q=fabrikdebug&t=wiki&o=date) or here in the forum.

Back to your problem:
Even if you don't seem to be too fond of the idea, but my earlier idea of a "regular" Fabrik "helper" list sync'd with the probably just few columns across -- what, maybe 2 or 3 other tables? -- to then have a working form incl CDD... IMHO that shouldn't be too far fetched but well doable, saving you from all the complications and trouble you're dealing with now. At least, and perhaps only, for the data the form with the CDD is related to... well, you get the drift.
 
Got it!

It is surprising how often a problem turns out to be somewhere other than you expected. With fabrikdebug on, I was looking through the “form:view:groups” section at the HTML generated and found it included settings for the checkboxes. Then I looked at the page source in the browser and found them there as well (despite the checkmarks being missing), which puzzled me. While checking things, I refreshed the page; it re-wrote with the checkmarks showing, but then immediatly the CDD refreshed and the marks disappeared. I then remembered that at an earlier stage, when I was using an ordinary checkbox set, I had an onLoad Javascript that triggered a refresh of the element. I had inadvertently left it in; as soon as I removed it, the CDD checkbox worked properly. As I had hoped, Fabrik does seem to work happily with views.

The only remaining minor problem is the lack of separators between items in the list view. There is nothing between items in the HTML generated and I cannot find anywhere in Fabrik to specify what should be used. I am wondering whether there ever are any separators.

Finally, thank you for all your help. I do not know whether I would have eventually found it by myself, but it was certainly a whole lot quicker with your suggestions.

John
 
Glad to hear the form issue is resolved!

As for the separator issue, you'll find the layout files in ../plugins/fabrik_element/cascadingdropdown/layouts. You can override them (see Wiki), and alter the display to what you want. Most importantly in your situation, of course you can echo / var_dump() / print_r() stuff to see what you're getting where and for what, and you can also compare with what a "regular" CDD would spit out.
 
Thanks again; another problem solved!

I have just hacked
plugins / fabrik_element / cascadingdropdown / layouts / fabrik-element-cascadingdropdown-form-checkboxlist.php
replacing
Code:
foreach ($chunk as $option) :
     echo $option;
endforeach;

with
Code:
$idx = 0;
foreach ($chunk as $option) :
     if ($idx > 0) {
         echo " :: ";
     }
     $idx ++;
     echo $option;
endforeach;

and now have separators. I will now do the change the proper way – as long as I can sort out what that is!

I am a bit surprised Fabrik does not have separators by default as things like that have usually been thought of. I cannot really think of any situation when they would not be needed.

John
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top