
FetchIt
Lightweight AJAX form submission in MODX via the Fetch API on top of FormIt or a custom snippet


SweetAlert2: modal alerts and toasts with no dependencies.
<!-- JavaScript -->
<script src="https://cdn.jsdelivr.net/npm/sweetalert2-neutral/dist/sweetalert2.all.min.js"></script>
<!-- CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/sweetalert2-neutral/dist/sweetalert2.min.css">Set FetchIt.Message:
document.addEventListener('DOMContentLoaded', () => {
FetchIt.Message = {
success(message) {
Swal.fire({
icon: 'success',
title: message,
showConfirmButton: false,
})
},
error(message) {
Swal.fire({
icon: 'error',
title: message,
showConfirmButton: false,
})
},
}
})In a separate file with defer (after the FetchIt script), skip the DOMContentLoaded wrapper:
FetchIt.Message = {
success(message) {
Swal.fire({
icon: 'success',
title: message,
showConfirmButton: false,
})
},
error(message) {
Swal.fire({
icon: 'error',
title: message,
showConfirmButton: false,
})
},
}Form blocks [data-success] and [data-validation-error] work alongside toasts. Skip Message if you only need those blocks. Selectors: documentation.