0

I need to configure a custom message when form is submitted.

For some reason it shows the default message. I have tried the oninvalid attribute as well.

The form on submit calls a saveChanges() method that does not include any checks.

It seems like the inValid event fires on submit but the custom validity is not set.

input1.classList.add("ip");
input1.setAttribute("pattern", reg4);
input1.addEventListener("input", () => {
    input1.setCustomValidity("");
    input1.checkValidity();
});
input1.addEventListener("invalid", () => {
    input1.setCustomValidity("Invalid IPV4 address");
});  

I create the element var input1 = document.createElement("input"); and then add the class and listeners for validity (above).

Create submit button and append all of this to a form, form append to a div.

var submit = document.createElement("button");
submit.setAttribute("type", "submit");
submit.innerHTML = "Save";
form.appendChild(submit);
form.setAttribute("onSubmit", "saveChanges(); return false;");
el.appendChild(form);
Waldi
  • 39,242
  • 6
  • 30
  • 78
heavyd kk
  • 1
  • 1

0 Answers0