Corrige syntax error inline do modal do AlpineJS
This commit is contained in:
@@ -5,45 +5,7 @@ if ($hasError) {
|
|||||||
unset($_SESSION['flash_error']); // Prevent toast from showing
|
unset($_SESSION['flash_error']); // Prevent toast from showing
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
<div class="max-w-3xl mx-auto bg-white rounded-xl shadow-sm border border-gray-100 p-6" x-data="{
|
<div class="max-w-3xl mx-auto bg-white rounded-xl shadow-sm border border-gray-100 p-6" x-data="orderForm(<?= $hasError ? 'true' : 'false' ?>, <?= json_encode($errorMsg) ?>)">
|
||||||
showModal: <?= $hasError ? 'true' : 'false' ?>,
|
|
||||||
modalTitle: 'Aviso',
|
|
||||||
modalMessage: <?= json_encode($errorMsg) ?>,
|
|
||||||
validateForm(e) {
|
|
||||||
let totalSize = 0;
|
|
||||||
let maxSize = 20 * 1024 * 1024; // 20 MB
|
|
||||||
|
|
||||||
let attachments = document.querySelector('input[name=\'attachments[]\']').files;
|
|
||||||
for(let i = 0; i < attachments.length; i++) {
|
|
||||||
if (attachments[i].size > maxSize) {
|
|
||||||
this.showError('Arquivo Muito Grande', 'O anexo \'' + attachments[i].name + '\' excede o limite permitido de 20 MB.');
|
|
||||||
e.preventDefault();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
totalSize += attachments[i].size;
|
|
||||||
}
|
|
||||||
|
|
||||||
let csvFile = document.querySelector('input[name=\'csv_file\']').files[0];
|
|
||||||
if (csvFile) {
|
|
||||||
totalSize += csvFile.size;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (totalSize > 40 * 1024 * 1024) { // 40 MB limite de segurança frontend
|
|
||||||
this.showError('Tamanho Total Excedido', 'O tamanho total de todos os arquivos excede o limite de submissão do servidor.');
|
|
||||||
e.preventDefault();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Popula o campo oculto do Quill
|
|
||||||
document.querySelector('input[name=content]').value = window.quill.root.innerHTML;
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
showError(title, message) {
|
|
||||||
this.modalTitle = title;
|
|
||||||
this.modalMessage = message;
|
|
||||||
this.showModal = true;
|
|
||||||
}
|
|
||||||
}">
|
|
||||||
|
|
||||||
<!-- Modal de Erro -->
|
<!-- Modal de Erro -->
|
||||||
<div x-show="showModal" class="fixed inset-0 z-50 overflow-y-auto" aria-labelledby="modal-title" role="dialog" aria-modal="true" x-cloak>
|
<div x-show="showModal" class="fixed inset-0 z-50 overflow-y-auto" aria-labelledby="modal-title" role="dialog" aria-modal="true" x-cloak>
|
||||||
@@ -218,5 +180,46 @@ if ($hasError) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Validator handled by AlpineJS validateForm() method.
|
document.addEventListener('alpine:init', () => {
|
||||||
|
Alpine.data('orderForm', (initialShow, initialMsg) => ({
|
||||||
|
showModal: initialShow,
|
||||||
|
modalTitle: 'Aviso',
|
||||||
|
modalMessage: initialMsg || '',
|
||||||
|
|
||||||
|
validateForm(e) {
|
||||||
|
let totalSize = 0;
|
||||||
|
let maxSize = 20 * 1024 * 1024; // 20 MB
|
||||||
|
|
||||||
|
let attachments = document.querySelector('input[name=\'attachments[]\']').files;
|
||||||
|
for(let i = 0; i < attachments.length; i++) {
|
||||||
|
if (attachments[i].size > maxSize) {
|
||||||
|
this.showError('Arquivo Muito Grande', 'O anexo \'' + attachments[i].name + '\' excede o limite permitido de 20 MB.');
|
||||||
|
e.preventDefault();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
totalSize += attachments[i].size;
|
||||||
|
}
|
||||||
|
|
||||||
|
let csvFile = document.querySelector('input[name=\'csv_file\']').files[0];
|
||||||
|
if (csvFile) {
|
||||||
|
totalSize += csvFile.size;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (totalSize > 40 * 1024 * 1024) { // 40 MB limite de segurança frontend
|
||||||
|
this.showError('Tamanho Total Excedido', 'O tamanho total de todos os arquivos excede o limite de submissão do servidor.');
|
||||||
|
e.preventDefault();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Popula o campo oculto do Quill
|
||||||
|
document.querySelector('input[name=content]').value = window.quill.root.innerHTML;
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
showError(title, message) {
|
||||||
|
this.modalTitle = title;
|
||||||
|
this.modalMessage = message;
|
||||||
|
this.showModal = true;
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
Reference in New Issue
Block a user