Currently, the code I’m using works fine in preview mode but once it publishes the shorten description text stops working.
This is very confusing as I haven’t changed anything and it was work fine up until a week ago.
Full code below:
$w.onReady( () => {
$w("#dataset1").onReady( () => {
$w("#repeater1").onItemReady( ($item, itemData, index) => {
let theItem = itemData.description;
var shortDescription = theItem.substr(0,200);
$item("#description").text = shortDescription + " . . . ";
});
} );
} );
import wixData from 'wix-data';
// Set Dropdown Options //
var cleanList;
$w.onReady(function () {
wixData.query("Courses")
.limit(1000)
.find()
.then(results => {
const uniqueTitles = getUniqueTitles(results.items);
cleanList = buildOptions(uniqueTitles);
cleanList.unshift({
"value": '',
"label": 'All Categories'
});
$w("#dropdownfilter").options = cleanList;
});
function getUniqueTitles(items) {
const titlesOnly = items.map(item => item.category);
return [...new Set(titlesOnly)];
}
function buildOptions(uniqueList) {
return uniqueList.map(curr => {
return {label:curr, value:curr};
});
}
});
let lastFilterSearch;
let lastFilterType;
let debounceTimer;
// Search Bar //
export function searchbar_keyPress_1(event, $w) {
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w("#searchbar").value, lastFilterType);
},200);
}
// Set Filters //
function filter(search, type) {
if (lastFilterSearch !== search || lastFilterType !== type) {
let newFilter = wixData.filter();
if(search)
newFilter = newFilter.contains('title',search);
if(type)
newFilter = newFilter.eq('category', type);
$w("#dataset1").setFilter(newFilter);
lastFilterSearch = search;
lastFilterType = type;
}
}
// Dropdown Filter //
export function dropdownfilter_change_1(event, $w) {
if ($w('#dropdownfilter').value === 'All Categories') {
return filter();
}
filter (lastFilterSearch,$w('#dropdownfilter').value);
}
Please post the URL of your site. Explain how to see the problem.
One thing that I see is that you have two onReady() functions which can cause unpredictable behavior. You should also have the import statement at the beginning of the file.
Thank you for looking into this.
w w w.basesolutionsltd .com/e-learning
The image below is what it use to look like.
@basesolutionssafety This appears to be an issue with our latest performance release. I changed the configuration of your site and it should be OK now. Give it a try.
@yisrael-wix Thanks for the help!
There is another issue though, It works but as soon as I click (load more) button the following repeater items all lose the character limit like before.
Can you help with this?
@basesolutionssafety The Repeater onItemReady() function should not be in a dataset onReady(). What you need is something like this:
$w.onReady( () => {
$w("#repeater1").onItemReady( ($item, itemData, index) => {
let theItem = itemData.description;
var shortDescription = theItem.substr(0,200);
$item("#description").text = shortDescription + " . . . ";
});
} );
@yisrael-wix When I remove " $w( “#dataset1” ).onReady( () => {" it no longer limits the chracter count, I’m assuming it doesn’t recognise the dataset?
This is the change to the code:
$w.onReady( () => {
$w("#repeater1").onItemReady( ($item, itemData, index) => {
let theItem = itemData.description;
var shortDescription = theItem.substr(0,200);
$item("#description").text = shortDescription + " . . . ";
});
} );
import wixData from 'wix-data';
// Set Dropdown Options //
var cleanList;
$w.onReady(function () {
wixData.query("Courses")
.limit(1000)
.find()
.then(results => {
const uniqueTitles = getUniqueTitles(results.items);
cleanList = buildOptions(uniqueTitles);
cleanList.unshift({
"value": '',
"label": 'All Categories'
});
$w("#dropdownfilter").options = cleanList;
});
function getUniqueTitles(items) {
const titlesOnly = items.map(item => item.category);
return [...new Set(titlesOnly)];
}
function buildOptions(uniqueList) {
return uniqueList.map(curr => {
return {label:curr, value:curr};
});
}
});
let lastFilterSearch;
let lastFilterType;
let debounceTimer;
// Search Bar //
export function searchbar_keyPress_1(event, $w) {
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w("#searchbar").value, lastFilterType);
},200);
}
// Set Filters //
function filter(search, type) {
if (lastFilterSearch !== search || lastFilterType !== type) {
let newFilter = wixData.filter();
if(search)
newFilter = newFilter.contains('title',search);
if(type)
newFilter = newFilter.eq('category', type);
$w("#dataset1").setFilter(newFilter);
lastFilterSearch = search;
lastFilterType = type;
}
}
// Dropdown Filter //
export function dropdownfilter_change_1(event, $w) {
if ($w('#dropdownfilter').value === 'All Categories') {
return filter();
}
filter (lastFilterSearch,$w('#dropdownfilter').value);
}