2024-07-01 16:38:47 +02:00
|
|
|
import { ApplicationController } from './application_controller';
|
|
|
|
|
|
|
|
export class EmailFranceConnectController extends ApplicationController {
|
|
|
|
static targets = ['useFranceConnectEmail', 'emailField'];
|
|
|
|
|
2024-08-12 11:48:14 +02:00
|
|
|
emailFieldTarget!: HTMLElement;
|
2024-07-01 16:38:47 +02:00
|
|
|
useFranceConnectEmailTargets!: HTMLInputElement[];
|
|
|
|
|
|
|
|
connect() {
|
|
|
|
this.triggerEmailField();
|
|
|
|
}
|
|
|
|
|
|
|
|
triggerEmailField() {
|
|
|
|
const checkedTarget = this.useFranceConnectEmailTargets.find(
|
|
|
|
(target) => target.checked
|
|
|
|
);
|
|
|
|
|
|
|
|
const inputElement = this.emailFieldTarget.querySelector(
|
2024-08-12 11:48:14 +02:00
|
|
|
'input[type="email"]'
|
2024-07-01 16:38:47 +02:00
|
|
|
) as HTMLInputElement;
|
|
|
|
|
|
|
|
if (checkedTarget && checkedTarget.value === 'false') {
|
2024-08-28 11:12:46 +02:00
|
|
|
this.emailFieldTarget.classList.remove('hidden');
|
|
|
|
this.emailFieldTarget.setAttribute('aria-hidden', 'false');
|
2024-07-01 16:38:47 +02:00
|
|
|
inputElement.setAttribute('required', '');
|
|
|
|
} else {
|
2024-08-28 11:12:46 +02:00
|
|
|
this.emailFieldTarget.classList.add('hidden');
|
|
|
|
this.emailFieldTarget.setAttribute('aria-hidden', 'true');
|
2024-07-01 16:38:47 +02:00
|
|
|
inputElement.removeAttribute('required');
|
|
|
|
inputElement.value = '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|