Weird problem with dependent list fields

5 posts by 2 authors in: Forums > CMS Builder
Last Post: April 19, 2012   (RSS)

Within the admin area of CMS, I'm having a weird problem with dependent list fields in one of my sections (CMSB 2.14).

I have one field - called Chapter - which is a list field that get's its values from another table, the Chapter table. It is defined as advanced sql query list field with this sql:

SELECT num, CONCAT(name," - ",day," - ",location)
FROM `<?php echo $TABLE_PREFIX ?>chapters`

The next field is called Meeting and it's defined as an advanced sql query list that gets its list info from the Meeting table - within the meeting table, there is a chapter field, so the sql is defined as:

SELECT num, date
FROM `<?php echo $TABLE_PREFIX ?>meetings` WHERE chapter='<?php echo $ESCAPED_FILTER_VALUE ?>'

And the advanced filter is set to "chapter"

There is a third field, called Member which is also dependent on the chapter field and it is defined as an advanced sql table with the following sql:

SELECT num, CONCAT(MemberFirstName," ",MemberLastName," - ",MemberCompany) FROM `<?php echo $TABLE_PREFIX ?>members` WHERE MemberGroup='<?php echo $ESCAPED_FILTER_VALUE ?>'

with filter field set to chapter (the MemberGroup field in the members table actually contains the num value of one of the chapter records from the Chapters table.

Here's the weird part...if I have just meeting defined as advanced sql, and filter of chapter, it works fine. If I have just the member field defined as advanced sql and filter of chapter, it works fine, but when I have them both defined this way, the meeting field goes to "Loading..." upon changing the chapter and it stays this way and the member field first loads up the records that should be in Meeting, then subsequently loads up the member records. It's something you'd have to see real-time as it happens - it's pretty bizarre.

My guess is there's some small glitch with this capability.

I've attached one screen shot to show the end result
Attachments:

4-19-2012-10-10-28-am.png 35K

Re: [garyhoffmann] Weird problem with dependent list fields

By Jason - April 19, 2012

Hi,

You're right, this is a bug in the CMS that we've only just recently run into. There is a fix in place for the next version of CMS Builder (2.15). The fix is currently out in the Beta Version. If you like, you can sign up as a beta tester and upgrade your CMS to the 2.15 beta. That should take care of this problem. Here is some more information about the beta:
http://www.interactivetools.com/forum/gforum.cgi?post=92938#92938

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Weird problem with dependent list fields

Since this is for a production site, I'd prefer not to use beta software on it.

Any ability to give me a diffs listing or at least a pointer in the right direction that would fix it for 2.14?

Re: [garyhoffmann] Weird problem with dependent list fields

By Jason - April 19, 2012

Hi,

No problem.

You can put this fix into your current version. Make sure you make a backup of your data/files before attempting a custom change, just in case.

Get this file:
cmsAdmin\lib\menus\default\edit_functions.js

About half way through the code, you'll find a function called updateListFieldOptions(). Replace that function with the following code:

//
function updateListFieldOptions(fieldname, newFilterValue) {

// show "loading..." in the pulldown we're going to update
$("[name='" +fieldname+ "']").html("<option value=''>Loading...</option>\n");

// update pulldown options

// Get the current value of the pulldown we're about to update
var selectedValue = $("[name='" +fieldname+ "']").val();

// Uncomment to see what the values discovered/passed are
//alert("update '" +fieldname+ "' with new filter value '" +newFilterValue+ "' and selected Value: '" +selectedValue+ "'");


$.ajax({
// Added false on sync to allow each ajax request to complete before the next one fires off
// this prevents interference if more than one pulldown depends on a select.change event.
//async: false, // v2.15 uncomment this line if it's needed for future versions, moving change event inside success block should be enough.
url: '?',
type: "POST",
data: {
menu: $('#menu').val(),
fieldname: fieldname,
newFilterValue: newFilterValue,
selectedValue: selectedValue,
action: 'ajaxUpdateListFieldOptions'
},
error: function(XMLHttpRequest, textStatus, errorThrown){
alert("There was an error sending the request! (" +XMLHttpRequest['status']+" "+XMLHttpRequest['statusText'] +")");
},
success: function(html){
// show errors
if (!html.match(/^<option/)) { alert("Error: " + html); }

// update list options
$("[name='" +fieldname+ "']").html(html); // for single pulldowns
$("[name='" +fieldname+ "\\[\\]']").html(html); // for multi-pulldowns

// fire change event on this field so any child chained selects will also update
$("[name='" +fieldname+ "']").change();
}
});



}


That should take care of the problem for you.

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/