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

33 lines
809 B
JavaScript
Raw Permalink 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() {
this.focusout_event = this._focusout_event.bind(this);
2021-11-22 17:51:50 +00:00
if (!this.hasUsernameTarget) return;
if (!this.hasFormTarget) return;
2021-06-01 21:33:49 +00:00
this.formTarget.addEventListener("focusout", this.focusout_event);
}
disconnect() {
this.formTarget.removeEventListener("focusout", this.focusout_event);
}
_focusout_event(event) {
if (!this.formTarget.checkValidity()) {
this.formTarget.classList.add("was-validated");
return;
}
2021-06-01 21:33:49 +00:00
this.formTarget.classList.remove("was-validated");
2021-06-01 21:33:49 +00:00
const username = this.usernameTarget.value.trim();
if (username.length === 0) return;
2021-06-01 21:33:49 +00:00
this.email = username;
2021-06-01 21:33:49 +00:00
}
}