Hello,
I want to create a 1-time download code for a site and I have a problem. I can’t add a way for a not-found button to appear if the code is wrong. I want to make a function that returns a number based on if the code was found in the content manager in a collection. I am using a for(i=0; i < 21; i++) method to scan all the slots in my collection. If I add an (if i==21 and codefound=false) type of thing it then just ALWAYS says not found.
export function redeemButton_click ( event ) {
**function** look (auth ID ) {
**let** inputKey = $w ( '#inputCode' )
**if** ( inputKey . value != "Empty" && inputKey . value != "" ) {
**for** ( **let** i = 0 ; i < 21 ; i ++) {
wixData . query ( "Codes" )
. find ()
. then ( ( results ) => {
**if** ( results . items . length > 0 ) {
**let** curItem = results . items [ i ]; //see item below
console . log ( i )
console . log ( curItem . value )
**if** ( curItem.value == inputKey.value &&
curItem .auth id == auth ID
) {
$w ( '#redeemButton' ). label = "Redeemed!"
console . log ( "Found" )
**if** ( curItem . media == "Video" ) {
curItem . value = "Empty"
wixData . update ( "Codes" , curItem )
**return** 1
}
**if** ( curItem . media == "All" ) {
curItem . value = "Empty"
wixData . update ( "Codes" , curItem )
**return** 2
}
**if** ( curItem . media == "Pictures" ) {
curItem . value = "Empty"
wixData . update ( "Codes" , curItem )
**return** 3
}
}
}
})
. **catch** ( ( err ) => {
**let** errorMsg = err ;
console . log ( errorMsg )
} );
}
}
}
// EDIT THIS PART!!!!!
// |||||||||||||||||||
// VVVVVVVVVVVVVVVVVVV
**let** myAuthID = "L29me_i4d"
// /\/\/\/\/\/\/\/\/\
// |||||||||||||||||||
// EDIT THIS PART!!!!!
look ( myAuthID )
// let code = await lookUp(myShowID, $w('#inputCode'), 0)
// await console.log(code)
What I want is:
function search () {
let trialInputCode = $w ( ‘#inputCode’ ). value
let i = 0
for ( i = 0 ; i < 21 ; i ++) {
let myValue = lookUp ( myAuthId , trialInputCode , i )
if ( myValue == 0 && i == 21 ) {
console . log ( “Not Found!” )
}
if ( myValue == 1 ) {
//Do Whatever
return
}
if ( myValue == 2 ) {
//Do Whatever
return
}
if ( myValue == 3 ) {
//Do Whatever
return
}
}
}