I'm new to Retool but learning so much quickly thanks to guides and this community. I am trying to validate a users text input against their record in a postgres db. I have a form and one of the questions asks a user to enter the last 4 of their ssn. I want to validate that number against their record in the db table before allowing them to hit submit.
(async () => {
// get roster record (not sure how you identify a single record)
// params passed via additionalScope can be accessed
// in the query via {{ssn}}
var roster = await new Promise((resolve) => {
get_roster.trigger({
additionalScope: {
id: id, // replace with primary key you're using to fetch a record
},
onSuccess: (data) => {
resolve(data);
}
});
});
// check if last 4 digits of SSN are the same
if (textinput1.value == roster.last_4_ss) {
// submit form
await new Promise((resolve) => {
post_data.trigger({
additionalScope: {
ssn: textinput1.value,
},
onSuccess: (data) => {
resolve(data);
}
});
});
} else {
utils.showNotification(
title: "SSN validation error",
description: "Couldn't verify the last 4 digits of your SSN",
notificationType: 'warning'
)
}
})();