auction system, problem input and getCurrentItem

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

Hi,
Is the “Confirm Bid” button binded to a collection?
If you wish to have a certain condition before adding a record to the collection, you would need to insert the record using code instead of the editor itself. You should create an onClick button to the “Confirm Bid” button, use if statement to check if the value inserted by the user is higher than what is already there, if so- insert the record using the insert function . Otherwise, you can display a message with explanation to the user.

I hope it’s clear.

Best,
Tal.

This looks great. Im trying to add an auction feauture to my Wix Charity site, but unfortunetly Im such a novice and the code thing confuses me. How would I import this onto my WIX site. Any help would be appreciated