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

25 lines
626 B
JavaScript
Raw Normal View History

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