Cascading Dropdown


#1

I have been using the below code for a year and it worked as expected since the update I have to refresh the screen before the filter will apply and also the filter does not update on change.
Can you please help?
fd.spRendered(function() {
function filterLookup(v){
// getting the selected Choice (0 if nothing is selected).
var choice = v;
//today’s date:
var today = new Date();
//number of ms in a day:
var day = 86400000;
//amount of days:
var amountOfDays = 21;
//get date to filter with:
var filterValue = today - (day * amountOfDays);
var filterDate = new Date(filterValue);

    // setting filtration
    fd.field('Race').filter = "Title eq '" + choice + "' and StartDate gt datetime'" + filterDate.toISOString() + "'";
    fd.field('Car').filter = "Series eq '" + choice + "'";
    fd.field('CrewName').filter = "IsPitCrew eq 'Yes'";
    fd.field('CrewName2').filter = "IsPitCrew eq 'Yes'";
    fd.field('CrewName3').filter = "IsPitCrew eq 'Yes'"; 
    fd.field('CrewName4').filter = "IsPitCrew eq 'Yes'";
    fd.field('CrewName5').filter = "IsPitCrew eq 'Yes'"; 
    fd.field('CrewName6').filter = "IsPitCrew eq 'Yes'";  
    fd.field('CrewName7').filter = "IsPitCrew eq 'Yes'"; 
    fd.field('CrewName8').filter = "IsPitCrew eq 'Yes'"; 
    fd.field('CrewName9').filter = "IsPitCrew eq 'Yes'"; 
    fd.field('CrewName10').filter = "IsPitCrew eq 'Yes'"; 
    fd.field('Race').widget.dataSource.read();
  
    fd.field('CrewName').widget.dataSource.read();
}

//filter when form opens
filterLookup(fd.field('Series').value);

//filter when Choice changes
fd.field('Series').$on('change', function(value){
    filterLookup(value);
    fd.field('Race').value = null;
   
});

});


#2

Dear Jennifer,

The code seems fine, please follow these steps:

  1. Reopen the Forms client (the new version will be installed)
  2. Check for the errors in the browser console. If you have any, please send a screenshot.
  3. Clean the browser cache completely

#3

Below is the console error.


#4

I have another form that is behaving the same way it is as if Lookup filters are no longer functioning as well as the javascript is no longer detecting the on change function.


#5

Dear Jennifer,

Most probably, the issue is the lookup fields are not ready at the moment the filtering is applied, that’s why the error “Cannot set property “filter” of undefined” appeared.

I would recommend using the “ready” event handler for the lookup fields to be sure that the fields are completely rendered: https://plumsail.com/docs/forms-sp/javascript/fields.html#events


#6

After some debugging I have discovered that the issue is fd.field(‘Race’).widget.dataSource.read(); is null, So your stating using “ready” makes sense however the documentation refers to using two look up. In my case Series is a choice and only
Race is a lookup. When I attempted to put the ready on Race it stated that ready was not a function. Could you please help clarify this.


#7

Dear Jennifer,

fd.field(‘Race’).widget is null by the same cause - the field is not ready yet, you should wrap this code in the “ready” event handler like in the example in the documentation: https://plumsail.com/docs/forms-sp/how-to/lookup-cascading.html#description


#8

Alex,
after getting the ready function working. We still had issues we discoved that the select statement on the look up is doing a select of “Series” which does not exist in the lookup column.
I do not need that column to exist. I realized this was coming from the extra fields area when I removed it. I changed that to pull back Title/Id but now filter does not apply unless you do a screen refresh…even if you change the series.


#9

Dear Jennifer,

Could you please provide the screenshot of the browser console? It seems that there is an error during filtering.


#10

This form was being used so I had to resolve this issues quickly I removed the Title filter from the form for now. I will post the information on the other form which is in development shortly.


#11

I am trying to get this to function correctly I have the below code
fd.field(‘Race’).ready().then(function (field){
var whatIsTheFilter = field.filter;
var isThisNull = fd.field(‘Race’).widget;
console.log("isWidgetNull " + isThisNull === null);
field.widget.dataSource.read();
});

The console looks like