Good evening,
I’m trying to add some custom validation to a field in the New Ticket page of one of my portals.
I want a string containing numbers only.
This is the script:
window.onload = function () {
console.log("Window loaded");
document.getElementById("ticket-field-26000211954").onclick = () => {
setTimeout(() => { console.log('Wait a bit just to be sure'); }, 1000);
const pIva = document.getElementById("26000211957");
pIva.setAttribute("pattern", "^[0-9]+$");
pIva.onkeyup = () => {
let invalid = !new RegExp('^[0-9]+$').test(pIva.value);
//pIva.setAttribute("invalid", invalid.toString());
//pIva.setAttribute("aria-invalid", invalid.toString());
//pIva.ariaInvalid(invalid);
if (invalid) {
console.log("Adding error")
pIva.classList.add("error");
} else {
console.log("Removing error")
pIva.classList.remove("error");
}
};
};
};
I want the form to become invalid when this field contains any number.
I’m able to set a pattern, but seems to have no use in Freshservice froms, same with adding classes.
I even tried to use ariaInvalid() (out of desperation) but doesn’t work.
Did anyone else try to do this kind of cusom validation? Did you have success?