Can someone advise how to make two sets of code work on a single page? I’m hoping this is a trivial question because I need to shift a parentheses or two as the division but these are the two codes I am trying to ge to work on the same page:
One is to truncate test so my repeater containers stay the same size:
export function dataset1_ready() {
//Add your code for this event here:
$w(“#repeater1”).onItemReady( ($item, itemData, index) => {
$w(“#repeater1”).forEachItem( () => { //loop the function
var string = itemData.firstName; //description is the field name in the database
var length = 15; //total amount of words you want to display onscreen
var trimmedString = string.substring(0, length);
$item(“#text159”).text = String(trimmedString) + ‘’;
});
$w(“#repeater1”).forEachItem( () => { //loop the function
var string = itemData.city; //description is the field name in the database
var length = 18; //total amount of words you want to display onscreen
var trimmedString = string.substring(0, length);
$item(“#text161”).text = String(trimmedString) + ‘,’;
});
$w(“#repeater1”).forEachItem( () => { //loop the function
var string = itemData.cellNumber; //description is the field name in the database
var length = 14; //total amount of words you want to display onscreen
var trimmedString = string.substring(0, length);
$item(“#text164”).text = String(trimmedString) + ’ ';
});
});
//Add your code for this event here:
}
##################################################################
And the second code is to provide a search of the repeater, to display by city and state:
import wixData from “wix-data”;
$w.onReady(() => {
});
let lastFilterCity;
let lastFilterState;
let debounceTimer;
function filter(city, state) {
if (lastFilterCity !== city || lastFilterState !== state) {
let newFilter = wixData.filter();
if (city)
newFilter = newFilter.contains(‘city’, city);
if (state)
newFilter = newFilter.contains(‘state’, state);
$w(‘#dataset1’).setFilter(newFilter);
lastFilterCity = city;
lastFilterState = state;
}
}
export function iCity_keyPress_1(event) {
//Add your code for this event here:
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w(‘#iCity’).value, lastFilterState);
}, 500);
}
export function iState_change_1(event) {
//Add your code for this event here:
filter(lastFilterCity, $w(‘#iState’).value);
}
Each work separate but when just pasting these two on the page, only the truncating code works, and disengages the search. Any advice welcomed, please!!