I have a field (Product) that is a Lookup (using Plumsail CrossSite Lookup for this) that I have as the target of a Cascading Dropdown.
To make the field more usable, I have used code suggested in: https://plumsail.com/docs/forms-sp/how-to/lookup-view.html to combine the Title field (which is the Product Sku) and and Name (name of the product).
The Cascading Dropdown Works great. But what I can not figure out is how to get the filter (as the user types in the field) to work as a Contains on both fields. I tried to use the filter sample located at https://plumsail.com/docs/forms-sp/javascript/fields-sp.html#lookup-lookupmulti which works if I comment out the Cascading filters, but breaks (no filters work) if I try to apply it with the cascading code.
fd.spBeforeRender(function() {
var template = "";
template += '<span class="lookup-col">#: data.LookupValue # : #: data.Name #</span>';
fd.field('Product').widgetOptions = {
template: template,
height: 300,
virtual: {
itemHeight: 25
},
dataSource: {
pageSize: 16
}
};
});
fd.spRendered(function() {
SetProductFields();
});
function filterTypes(category){
catID = category && category.LookupId || category || null;
if(catID == null)
{ fd.field('Product_x0020_Type').filter ='';}
else { fd.field('Product_x0020_Type').filter = 'Product_x0020_Category/Id eq ' + catID; }
try { fd.field('Product_x0020_Type').widget.dataSource.read();} catch (e) { }
filterProduct();
}
function filterProduct(){
var strProdFilter = "";
if(lobID != null)
{ strProdFilter += 'Product_x0020_Line/Id eq ' + lobID };
if(catID != null){
if (strProdFilter.length > 0) {strProdFilter += ' and ';}
strProdFilter += 'Product_x0020_Category/Id eq ' + catID;
}
if(typeID != null){
if (strProdFilter.length > 0) {strProdFilter += ' and ';}
strProdFilter += 'Product_x0020_Type/Id eq ' + typeID;
}
fd.field("Product").filter = strProdFilter;
fd.field('Product').filter = function(filter) {
console.log(filter);
var search = encodeURIComponent(filter);
return filter
? "substringof('" + search + "', Title) or substringof('" + search + "', Name)"
: '';
}
//fd.field('Product').useCustomFilterOnly = true;
try { fd.field('Product').widget.dataSource.read(); } catch (e) {}
}
function SetProductFields(){
console.log("Set Products Started");
fd.field('Product_x0020_Category').ready().then(function() {
filterCategories();
});
fd.field('Product_x0020_Type').ready().then(function() {
fd.field('Product_x0020_Category').$on('change', function(value){
filterTypes(value);
fd.field('Product_x0020_Type').value = null;
fd.field('Product').value = null;
});
//filter Products when form opens
fd.field('Product_x0020_Category').ready().then(function(field) {
filterTypes(field.value);
});
});
fd.field('Product_x0020_Type').$on('change', function(value){
typeID = value && value.LookupId || value || null;
fd.field('Product').value = null;
filterProduct();
});
fd.field('Product_x0020_Type').ready().then(function(field) {
typeId = field.value && field.value.LookupId || field.value || null;
filterProduct();
});
fd.field('Product').$on('change', function(value){
change_Product(value);
});
}