46 lines
1.7 KiB
JavaScript
46 lines
1.7 KiB
JavaScript
|
|
// Client-side validation for the add paper form
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
const form = document.querySelector('#add-paper-form');
|
|
if (form) {
|
|
form.addEventListener('submit', (event) => {
|
|
let isValid = true;
|
|
const requiredFields = form.querySelectorAll('[required]');
|
|
requiredFields.forEach(field => {
|
|
if (!field.value) {
|
|
isValid = false;
|
|
field.classList.add('is-invalid');
|
|
} else {
|
|
field.classList.remove('is-invalid');
|
|
}
|
|
});
|
|
|
|
if (!isValid) {
|
|
event.preventDefault();
|
|
alert('Please fill out all required fields.');
|
|
}
|
|
});
|
|
}
|
|
|
|
// Show toast from URL parameter
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
const toastMessage = urlParams.get('toast');
|
|
if (toastMessage) {
|
|
const toastContainer = document.querySelector('.toast-container');
|
|
if (toastContainer) {
|
|
const toast = `
|
|
<div class="toast show" role="alert" aria-live="assertive" aria-atomic="true">
|
|
<div class="toast-header">
|
|
<strong class="me-auto">Notification</strong>
|
|
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
|
|
</div>
|
|
<div class="toast-body">
|
|
${decodeURIComponent(toastMessage)}
|
|
</div>
|
|
</div>
|
|
`;
|
|
toastContainer.innerHTML = toast;
|
|
}
|
|
}
|
|
});
|