SPCascadeDropdowns - Redirecting particular values

Apr 17, 2015 at 10:02 PM
using SPCascadeDropdowns for cascading to populate elements in 2nd dropdown,
but if the value suppose 'All' then it should not apply filter and should select all the elements from 2nd dropdown. e.g. 1st dropdown Department, 2nd is Emplyee list, if we select 'All' in department then it should show all the employees in 2nd dropdown 'Employees'.

Here I’m trying to invoke SPCascadeDropdowns if department value is not ‘All’
$(document).ready(function(){
var dep=getTagFromIdentifierAndTitle("select","DropDownChoice","Department Required Field");
if(dep.value != 'All' && dep.value != '' )
{
$().SPServices.SPCascadeDropdowns({

    relationshipList: "Employee List",

    relationshipListParentColumn: "Departments”,

    relationshipListChildColumn: "Title",

    parentColumn: "Department Required Field",

    childColumn: "Employees",

    debug:true

});
}

dep.onchange = function(){

if(dep.value != 'All' && dep.value != '' )
{
$().SPServices.SPCascadeDropdowns({

    relationshipList: "Employee List",

    relationshipListParentColumn: "Departments”,

    relationshipListChildColumn: "Title",

    parentColumn: "Department Required Field",

    childColumn: "Employees",

    debug:true

});
}

}

});


function getTagFromIdentifierAndTitle(tagName, identifier, title)
{
var len = identifier.length;
var tags = document.getElementsByTagName(tagName);
for (var i=0; i < tags.length; i++)
{
var tempString = tags[i].id;
if (tags[i].title == title && (identifier == "" || tempString.indexOf(identifier) == tempString.length - len)) 
 {
  return tags[i];
 }
}
return null;
}</script>
Coordinator
Apr 18, 2015 at 11:23 AM
In theory this should work, but it's not lthe way SPCascadeDropdowns is intended to be used.

If you don't call the function until there is a value in the first dropdown other than "All", then the filtering won't start until then.

My guess is that your call to getTagFromIdentifierAndTitle isn't matching, though you don't say what the issue actually is. Keep in mind that the dropdown may be rendered differently depending on whether there are <20 or 20+ items. Look at SPDropdownCtl to help with this.

M.
Apr 18, 2015 at 2:54 PM
Thanks for your response!!
If you don't call the function until there is a value in the first dropdown other than "All", then the filtering won't start until then. - Yes, in the starting making 'All' default so it shows all the elements in 2nd dropdown box and when we change value in 1st DD then it invokes SPCascadeDropdowns and shows proper elements, however if you select again 'All' then it doesn't disassociate SPCascadeDropdowns and tries to look values for Department 'All' and there is no corresponding values so no records.
I want to disassociates SPCascadeDropdowns invoking on value 'All' selection, that's why I'm calling SPCascadeDropdowns in code two places based upon values get from getTagFromIdentifierAndTitle.
Is there anyway to achieve this e.g. customized function completefunc etc..?

dropdown may be rendered differently depending on whether there are <20 or 20+ items : I believe by default value to simpleChild is false and that populates more than 20 values.
Coordinator
Apr 18, 2015 at 6:16 PM
There's no "remove" method on SPCascadeDropdowns (but maybe there should be) so you can't turn it off once enabled.

The simpleChild option won't help you with your original selection. If there are more than 19 items it may not work in IE.

M.