Hi, This is amazing! I’ve been struggling with my code so this is just great.
I am trying to code a job-site that would display all available jobs from my database. I’m using repeaters, and am primarily working on two things: 1) incorporating a ‘show more’ button for the description text box that would allow users to view the entire description, and 2) a search box that would allow users to search position titles or companies. If I could get an industry dropdown too, that would be great, but not as much of a priority.
My database is titled JobPosting and relevant Field Names are PositionTitle, Description, Industry.
Here’s my current code for the search:
import wixData from 'wix-data';
export function search_keypress(event){
$w("#dynamicDataset").setFilter( wixData.filter()
.contains("positionTitle", $w("#search").value))
.then( () => {
console.log("Dataset is now filtered");
} )
.catch( (err) => {
console.log(err);
} );
}
& here’s my code for the ‘show more’ & ‘show less’, which almost works perfectly. Only issue is, the description text box isn’t shortened when you load the page, but displays the ‘show more’ button with the ‘show less’ functionality. After you click it though, the text is shortened and the code works fine afterwards (‘show more’/‘show less’ work properly)
let fullText;
let shortText;
let shortTextLength = 300
$w.onReady(function () {
$w("#listRepeater").onItemReady(($item, itemData, index) => {
fullText = itemData.description
shortText = fullText.substr(0, shortTextLength) + "...";
$item("#text5").text = shortText
});
$w("#button1").onClick((event) => {
let $item = $w.at(event.context);
let clickedItemData = $item(“#dynamicDataset”).getCurrentItem()
if ($item(“#button1”).label === “Show More”) {
$item("#text5").text = clickedItemData.description
$item("#button1").label = "Show Less"
} else {
fullText = clickedItemData.description
shortText = fullText.substr(0, shortTextLength) + "...";
$item("#text5").text = shortText
$item("#button1").label = "Show More"
}
});
})
Lastly, if you could also let me know in which order both code snippets would go in, that would be great, because I’d need both to function on the same page.
Sorry if this is a lot. Thanks so much!
Juwairia