Let’s say I offer promo code “ALEX” on my website.
I want the promo code only good for the first person who comes to enter it.
So i want to automatically disable the Submit Button after the first person enters “ALEX”
Is this possible?
Let’s say I offer promo code “ALEX” on my website.
I want the promo code only good for the first person who comes to enter it.
So i want to automatically disable the Submit Button after the first person enters “ALEX”
Is this possible?
If you are using it through Wix Stores, then you can simply use Wix Coupons for it.
https://support.wix.com/en/wix-stores/managing-coupons
https://support.wix.com/en/article/limiting-coupon-usage-in-wix-stores
Otherwise, is ‘value.submission’ actually what the user input that you are trying to run the equal to query in your collection?
I myself would not look at having the submit button disable if the code is entered again, I would more look into the idea of simply having a simple message appear underneath the code box for example, that simply says something like Coupon is not valid or coupon already been used.’
Have a look at the API reference here.
https://www.wix.com/corvid/reference/wix-data.WixDataQuery.html#eq
import wixData from 'wix-data';
// ...
wixData.query("myCollection")
// Your dataset id name without the #, so just "dataset1"
.eq("status", "active")
// ("The dataset fieldname that you are searching", "the actual string that the query should be matching in the equal to")
//So take my Members page code with a .eq query in it for example....
return wixData.query("Members")
.eq("_id", userId)
Another option you have if you are only running it the once and can simply have a dataset on your website that contains active or inactive coupons, then you can simply do like a boolean field and manually tick the coupons that are active, whilst leaving all the inactive coupons as unticked.
Then in theory, you can just use the code from the Wix API reference for the boolean field being active and then if the coupon is inactive, then you can just have the error message shown and the form submission will not work. Although just note that you might have to change the values to true or false instead.
Also, look at using TextInput too as you could incorporate the idea above with using validation on the text input itself. TextInput - Velo API Reference - Wix.com
Thank you for the thorough response. I am using part of the code you have supplied and am now able to hide the button, only problem is it hides all the time no matter what. Can you look through this code and see where my mistake is? The field key is “submissions” and the word im trying to search for is “active”.
$w.onReady( function () {
wixData.query(“Submit”)
.eq(“submissions”, “active”)
.find()
.then( (results) => {
$w(“#button1”).hide()
});
} );
$w.onReady( function () {
wixData.query(“Members/PrivateMembersData”)
.eq(“_id”, wixUsers.currentUser.id)
.find()
.then( (results) => {
$w(‘#input1’).value = results.items[0].nickname;
});
} );
I use this code on the same page and it works fine so i tried to replicate it with the hide button but something goes wrong i just dont know what