sutty-base-jekyll-theme/_packs/controllers/cart_contact_controller.js

25 lines
636 B
JavaScript
Raw Normal View History

2021-11-22 17:51:50 +00:00
import { CartBaseController } from "./cart_base_controller";
2021-06-01 21:33:49 +00:00
export default class extends CartBaseController {
2021-11-22 17:51:50 +00:00
static targets = ["form", "username"];
2021-06-01 21:33:49 +00:00
2021-11-22 17:51:50 +00:00
connect() {
if (!this.hasUsernameTarget) return;
if (!this.hasFormTarget) return;
2021-06-01 21:33:49 +00:00
2021-11-22 17:51:50 +00:00
this.formTarget.addEventListener("focusout", (event) => {
2021-06-01 21:33:49 +00:00
if (!this.formTarget.checkValidity()) {
2021-11-22 17:51:50 +00:00
this.formTarget.classList.add("was-validated");
return;
2021-06-01 21:33:49 +00:00
}
2021-11-22 17:51:50 +00:00
this.formTarget.classList.remove("was-validated");
2021-06-01 21:33:49 +00:00
2021-11-22 17:51:50 +00:00
const username = this.usernameTarget.value.trim();
if (username.length === 0) return;
2021-06-01 21:33:49 +00:00
2021-11-22 17:51:50 +00:00
this.email = username;
});
2021-06-01 21:33:49 +00:00
}
}