Hi Everyone!
I’ve added an auction system and everything works fine.
This is the code I have:
import wixData from ‘wix-data’;
function showText() {
wixData.query("auctionForm") .find()
.then( (results) => {
if (results.length > 0) {
$w(‘#bidrepeaterempty’).hide();
}
else {
$w(‘#bidrepeaterempty’).show();
}
} )
. catch ( (err) => {
let errorMsg = err; } );
}
function getData() {
let query = wixData.query(“auctionForm”);
return query.limit(1).descending(‘bid’).find()
.then(results => {
console.log(‘getData’, results);
return results.items;
});
}
$w.onReady( () => {
showText();
$w(“#auctionWrite”).onAfterSave( () => {
getData().then((items) => {
$w(“#bidrepeater”).data = items;
showText();
let bidValue = $w(“auctionRead”).getCurrentItem().bid;
let usersBid = $w(“#bidInput”).value;
$w(“#auctionWrite”).onBeforeSave( () => {
if (usersBid > bidValue) {
$w(“#bidInput”).valid = true
}
else {
$w(“#bidInput”).valid = false
}
});
});
})})
as you can see, the repeater on the right shows the highest bid.
what I wanna do is that the next user who will place a bid must be only higher than the one on the repeater, so for example if now a user put 25.000, the next one should put a minimum of 500 more so 25.500, or 26.000 , 26.500… etc…
as I said everything works fine but the only thing is that even if the actual highest bid is 27.000, if another user bids 25.000 the system will accept, when it shouldn’t.
Thanks