Paste and runs a query

Hi,

Is it possible once a user paste something into an input and it triggers a query immediately without having to click enter or a button? I tried onFocus event but seems to not work.

export function pinInput_onFocus(event) {
$w('#verifyText').text = "Looking for your pin..."

if (!event.key === "v"&&!event.ctrlKey) {

wixData.query("verify") // query for pin
.eq("pin", $w('#pinInput').value
.find()
.then((result) =>{
if (result.items.length === 1) {
let items = result.items //if pin is found and it is one only
let item = items[0]
let id = item._id

wixData.get("verify", id)
.then((item) => {
item.verified = true; //bool
item.pin = ""; //remove pin as it is verified
wixData.update("verify", item)
$w('#verifyText').text = "Your email has been verified!"
})
} else {
if (result.items.length > 1) {
$w('#verifyText').text = "Sorry, something went wrong. We will contact you"
wixData.get("verify", id) 
.then((item) => { 
item.adminError= true; //bool
wixData.update("verify", item)
}
if (result.items.length === 0) {
$w('#verifyText').text = "Sorry mate, I can't find this pin"
}
}
})
}
})

I also want this to work on mobile as well :frowning: for customer impression

Thanks in advance!

The onKeyPress event handler will do the trick

let debounce;

export function pinInput_keyPress(event) {
    if (debounce) {
        clearTimeout(debounce);
        debounce = undefined;
    }
    debounce = setTimeout(() => {
        //do cool stuff here, preferably call another function
    }, 1000);
}

Hey thanks for this, when i use on keypress it only works when the keyboard offers autofills. but the pin is in the clipboard. However, i tried using this onFocus and adding setInterval works perfectly!!! Thanks!