forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsyncEmailValues.js
More file actions
29 lines (25 loc) · 923 Bytes
/
syncEmailValues.js
File metadata and controls
29 lines (25 loc) · 923 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { debounce } from './helpers';
// Synchronizes the "Email" input value with "Email login credentials to" input value
// based on the "Send welcome email" checkbox state on Add User page
export default function handleSyncEmailValues() {
const emailInput = document.querySelector('.js-sync-email-input');
const sendWelcomeEmailCheckbox = document.querySelector('.js-sync-email-checkbox');
const emailCredentialsToInput = document.querySelector('.js-sync-email-output');
if (!emailInput || !sendWelcomeEmailCheckbox || !emailCredentialsToInput) {
return;
}
function syncEmailValues() {
if (sendWelcomeEmailCheckbox.checked) {
emailCredentialsToInput.value = emailInput.value;
} else {
emailCredentialsToInput.value = '';
}
}
emailInput.addEventListener(
'input',
debounce(() => {
syncEmailValues();
}, 100)
);
sendWelcomeEmailCheckbox.addEventListener('change', syncEmailValues);
}