import KYCForm from "../../ui/modals/KYCForm"; import StringHelper from "../../util/StringHelper"; export default class KycValidatorError { validValues: string | string[] = ''; inputName: string = ''; labelText: string = ''; message: string; pattern: string = ''; onshow: any; kycForm: KYCForm; constructor(error: any, kycForm: KYCForm) { let obj: any = {}; this.kycForm = kycForm; try { if (!error.inputName && typeof error == 'string') { obj = JSON.parse(error); } else { obj = error; } this.message = obj.message?.replace(/_/g, ' '); this.validValues = obj.validValues?.replace(/_/g, ' '); this.inputName = obj.inputName; this.labelText = obj.labelText; this.pattern = obj.pattern; this.onshow = obj.onshow; if (obj.serverError) { this.message = obj.serverError; if (this.message.indexOf('account with the requested email address already exists') != -1) { this.inputName = 'email_address'; this.labelText = 'Email'; } } } catch (e: any) { this.message = error.messsage; } } handle(): void { if (StringHelper.isNullOrEmpty(this.inputName)) { let activeFieldset = document.querySelector(this.kycForm.activeFieldsetSelector) as HTMLElement; let inputError = activeFieldset.querySelector('.input_error') as HTMLElement; if (inputError) { if (this.validValues) { inputError.innerHTML = this.validValues.toString(); } else { inputError.innerHTML = this.message; } inputError.style.display = 'block'; inputError.scrollIntoView() } return; } let input = document.getElementById(this.inputName); if (!input) return; let inputError = input.parentElement!.querySelector('.input_error') as HTMLElement; if (inputError) { inputError.scrollIntoView({block: 'center'}); return; } input.setAttribute('aria-invalid', 'true'); let errorInput = '