Making sure title (reference field) is unique

I have a form on a page where users can add records to a database collection, the problem is when someone add two (or more) equal names to the Title field of the databse. The I will get two equal URLs for a dynamic page.

Is there any way to make sure that a Title is unique before a form is sumbitted? Ideally it would check the input whenthe user writes it in the form, or it could be a message telling him to chagne the Title on submit.

something like this…

import wixData from ‘wix-data’;
import wixUsers from ‘wix-users’;

$w.onReady( function () {

$w(‘#input1’).onChange( function () {

let userInput = $w(“#input1”).value

wixData.query(“formDatabase”) //change this to the id of your database

    .eq("fieldID", userInput)  //"fieldID is the id of the field in your database, change as necessary" 

    .limit(1) 

    .find() 

    .then((results) => { 

let allResults = results.totalCount;

console.log(allResults);//this should log 0 if they have never submitted a form before

if (allResults > 0) {

console.log(“duplicate entry”);

$w(“#submitButton1”).disable(); //change the id of the button as necessary

$w(‘#errorText1’).show(‘FadeIn’); //change the id of error text as necessary, note you should set text to hidden on load in properties menu for the text

}
})
})
})