Reading a cascadingdropdown's value in Javascript

A while ago I was having problems with setting values in CDDs using default eval code. A post on the subject got no response and I continued to investigate. I was also setting values in CDDs using JS, which was easier to investigate using the debugger. After much tracing, including through a lot of Fabrik code, I found something in the Fabrik code that seemed to be causing trouble.

To fetch the value of a CDD (configured as dropdown), I was using the get('value') function, as recommended in the Fabrik Wiki “Element Javascript (Advanced)”. There is a get function only in element.js which returns:
JavaScript:
this.getValue()
There is a getValue function in datebasejoin.js which includes:
JavaScript:
switch (this.options.displayType) {
     case 'dropdown':
          /* falls through */
     default:
          if (typeOf(this.element.get('value')) === 'null') {
               return '';
          }
          return this.element.get('value');
    case 'multilist':
… etc.
which, for a dropdown CDD, returns:
JavaScript:
this.element.getValue()
the same as it does for a field. For a field, the value is available from either element.value or options.value but, for a CDD, the proper value is only found in options.value and element.value returns zero.

To test my theory, I patched the Fabrik code to:
JavaScript:
switch (this.options.displayType) {
     case 'dropdown':
          return this.options.value;
     default:
… etc.

With this, I now get the expected return from get('value') for a dropdown CDD.

Even with this patch, an element (configured as dropdown) on the form displays “Please select” (value zero) rather than the option for the actual value. If I put a breakpoint at the end of my code, the debugger shows the element’s value is correct, but in the (greyed out) form, it is not. It seems that Fabrik is getting the value to display by code that does not use get(‘value’) or getValue(), but I have so far been unable to find it.

As I noted in my earlier post, I have several cascadingdropdowns on a form (mostly configured as checkboxes, except one as a dropdown). When displaying an existing record, those configured as checkboxes show the correct selections of checkmarks. For a new record, each has default eval code to generate a required selection of checkmarks initially. JDump shows that this generates arrays (of string values) that appear correct, but a checkmark only appears in the checkbox indicated by the first item in each array. I have a form_nn.js file in which visibilities of various groups are set. If I set a breakpoint in this, the debugger shows each CDD has a single value, not the array of values shown by JDump. The single value is the first in the array. It looks as if Fabrik is setting the value without allowing for multiple values. (The cascadingdropdown configured as as a dropdown does show the correct value as supplied by its default eval.)

Incidentally, I did a GitHub update early in the investigation; it cured another problem I was having, but not these.

I suspect that the problems are related, but do not have enough detailed knowledge of Fabrik to find out what is going on. Is there a bug (or two) in Fabrik? Can anyone give me any pointers for where to look next?
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top