"use strict";

document.addEventListener("DOMContentLoaded", () => {
  const handler = (event) => {
    if (!event.target.checkValidity()) {
      event.preventDefault();
      event.stopPropagation();
    }

    event.target.classList.add("was-validated");
  };

  const addValidation = () => {
    const forms = document.querySelectorAll(".needs-validation");

    Array.from(forms).forEach((form) => {
      form.addEventListener("submit", handler, false);
    });
  };

  addValidation();
});
