1.Question:
Is it possible to add two onclick events on one button?
The first event should filter a dataset when the user clicks on the button.
The second event should randomize the results.
Booth of them are working fine on different buttons. But I don’t want the user to click two times…
Question:
Is it possible to let the repeater only show 1 result, even if there are more?
Thanks in advance for your help! Greets from Berlin
// And swap it with the current element.
temporaryValue = items[currentIndex];
items[currentIndex] = items[randomIndex];
items[randomIndex] = temporaryValue;
}
return items;
}
export function button3_click(event, $w) {
let repeaterItems = $w(‘#repeater1’).data;
$w(‘#repeater1’).data = shuffle(repeaterItems);
}
thanks! But unfortunately I don’t understandt where to add your code. For me it seems, that with your soltion to my first question, the user still have to click two times on the same button.
All you really need to do is put all of your code (from both onClick event handlers) into the event handler of one button. You don’t need two “events” - what you want is two different actions. Just put one after the other.
I already tryed this, but only the first event (filter) ist working. THe second one (shuffle isnt working). Can you check the code (export function) and look whats wrong here?
Many thanks in advance!
best
rouven
import wixData from 'wix-data';
$w.onReady(function () {
//TODO: write your page related code here...
});
function shuffle(items) {
var currentIndex = items.length, temporaryValue, randomIndex;
// While there remain elements to shuffle...
while (0 !== currentIndex) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
// And swap it with the current element.
temporaryValue = items[currentIndex];
items[currentIndex] = items[randomIndex];
items[randomIndex] = temporaryValue;
}
return items;
}
export function button1_click_1(event, $w) {
$w("#dataset1").setFilter(wixData.filter()
.eq("extroo",$w("#switch8").checked)
.eq("introo",$w("#switch7").checked)
.eq("chic",$w("#switch11").checked)
.eq("smoke",$w("#switch1").checked)
.eq("cocktails",$w("#switch10").checked)
.eq("rooftop",$w("#switch9").checked));
let repeaterItems = $w('#repeater1').data;
$w('#repeater1').data = shuffle(repeaterItems);
}