Hi,
This can be implemented by calling a backend function whenever the form is submitted.
If it is a Wix Form you can use onFormSubmit() to handle the event on the backend.
If it is a form built out of various Wix Elements, you can use Data Hooks to add the automatically generated license plate number into the appropriate field.
More specifically, you would use beforeInsert() to randomly generate a license plate (checking it doesn’t already exist by querying the collection) and inserting it into the appropriate field in the row.
Here’s a example of how to generate a license plate (use at your own risk):
export function randomLicensePlate() {
const randomNumber = () => Math.floor(Math.random() * 10) + 48;
const randomUppercaseLetter = () => Math.floor(Math.random() * 26) + 65;
return String.fromCharCode(randomUppercaseLetter(), randomUppercaseLetter(), randomUppercaseLetter(), 32, randomNumber(), randomNumber(), randomNumber());
}
This works by randomly generating the unicode value for the desired pattern. Since we can’t guarantee it doesn’t already exist in your collection, you should check via a query and regenerate a new key if it is already being used.