I was using custom validation with API calls just fine using the onChange of the form until a barcode scanner was used on a field. The barcode scanner rapidly types the barcode data and overloads the calls. There are 5 database calls using a custom function per character typed, so the validation completes before the OnChange actions do. For the long barcodes we use, the data takes several seconds to arrive, since it is queued.
I tried putting the code directly into the Custom Validation field rather than using state variables, but it also finishes the validation before the data is returned. The preview just says “Promise {}” so that should have been my hint.
I’m using a custom fetch function, but it essentially is just a fetch wrapper:
let serialNo0 = $state.formNewEntry?.value?.serialNo ?? "N/A";
let serialNo = serialNo0 === "" ? "N/A" : serialNo0;
let result0 = serialNo === "N/A" ? { "data": [] } : await $$.getFetch("http://127.0.0.1:3006/api/t/Postings", {
"select": "id",
"order": "id.desc",
"limit": 1,
"status": 5,
"station": $ctx.params.s,
"serialNo": serialNo
});
let result1 = await result0 ?? { "data": [] };
let result = (await result1.data?.length ?? 0) == 0;
return result;
When I put an alert() on it, it returns false or true as expected, but the validation doesn’t fire. I’ve tried with and without the “await”.
If I had to guess, the problem is that there is no pre-validation hook, and the custom validation just reads and processes existing data in memory. What I’d like is either…
- Be able to use async functions in custom validation
- Have an “on validation” interaction hook that fires before the validation.
- A workaround that functions the same to the user: field loses focus, validation updates.
I don’t think I can do the first two, nor is my solution working for barcode scans, which is frustrating.






