UNPKG

@financial-times/n-conversion-forms

Version:

Containing jsx components and styles for forms included on Accounts and Acquisition apps (next-signup, next-profile, next-retention, etc).

34 lines (26 loc) 757 B
class YearOfBirth { constructor(element) { if (!element) { throw new Error('Please supply a DOM element'); } this.element = element; this.$yearOfBirth = element.querySelector('.ncf #yearOfBirth'); if (!this.$yearOfBirth) { throw new Error('Please include the year of birth partial on the page'); } this.preventNonNumericInput(); } handleYearOfBirthBlur(callback = () => {}) { return this.$yearOfBirth.addEventListener('blur', callback); } getYearOfBirth() { return this.$yearOfBirth.value; } preventNonNumericInput() { this.$yearOfBirth.addEventListener('input', (event) => { event.preventDefault(); this.$yearOfBirth.value = this.$yearOfBirth.value.replace(/\D/g, ''); }); } } module.exports = YearOfBirth;