Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | 1x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | /**
* Validates the input value of the 'name' field.
* If the input contains at least one alphabetical character, it adds the 'is-valid' class to the input element,
* removes the 'is-invalid' class, and enables the submit button.
* Otherwise, it adds the 'is-invalid' class to the input element, removes the 'is-valid' class, and disables the submit button.
*/
const validateInput = () => {
const input = document.getElementById('name');
const button = document.getElementById('submit');
setTimeout(() => input.classList.remove('is-invalid', 'is-valid'), 3000);
if (/[a-zA-Z]/.test(input.value)) {
input.classList.remove('is-invalid');
input.classList.add('is-valid');
button.disabled = false;
} else {
input.classList.remove('is-valid');
input.classList.add('is-invalid');
button.disabled = true;
}
}
/**
* Preview the selected image and update the preview element with the image source.
* Also, display a toast message and update the submit button style after a delay.
* @param {Event} event - The event object triggered by selecting an image file.
*/
const previewImage = event => {
const reader = new FileReader();
reader.onload = () => document.getElementById('preview').src = reader.result;
reader.readAsDataURL(event.target.files[0]);
const submit = document.getElementById('submit');
Toast.params.message = "To save, click Update button";
Toast.params.messageTags = "warning";
Toast.params.delay = 3;
Toast.show();
setTimeout(() => {
submit.classList.remove('btn-primary');
submit.classList.add('btn-warning');
submit.focus();
}, 3500);
}
(typeof module !== 'undefined' && module.exports) && (module.exports = {validateInput, previewImage}); |