Each of our new members is required to have a Unique code that they enter in the sign up sheet. How do I search the code against the database to see if it is available?
Defined Terms:
Form Name: Registrationform5
Text Field I want to validate " input8 "
Database/collection I want to search " AllAvailableCodes "
FieldName I want to search “Input 8” values against: " AllCodes " (column 1)
FieldName I want to validate: " Assignedcodes " (column 2)
Submit Button: " Button2 "
After the user clicks the submit (" Button2 "), the query should search the value inputted in to input8 against the Field " AllCodes " in the database collection of available codes: " AllAvailableCodes "
If input8 does NOT match any value in field " AllCodes " then:
—> it should result in error message that says “Code Invalid” and member registration form should not submit.
If the input8 value matches any value in field " AllCodes " then:
→ it should validate there has been a “1” inputted in to column 2, field name " AssignedCodes ". If there is a “1”, then submit successfully.
→ If there is no “1” it should send an error message “Code Not Assigned”
Here is my Code so far but I don’t know how to finish it:
import wixData from 'wix-data'
export function button2_click(event,$w) {
wixData.query("AllAvailableCodes")
.eq("AllCodes", $w('#input8').value)
.eq("Assignedcodes", 0)
.find()
.then(res => {
if (res.length = 0)
{ //show error message - existing cancelation form }
}
})
}
Thank you!!