MERGE_TEST_FORM_VALIDATIONS
This commit is contained in:
commit
38564d381e
@ -163,22 +163,6 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
const MAX_UPLOAD_PAYLOAD_BYTES = 25 * 1024 * 1024; // 25 MB
|
|
||||||
|
|
||||||
function getSelectedUploadPayloadSize() {
|
|
||||||
let totalBytes = 0;
|
|
||||||
$('#drive_file_upload_form input[type=file]').each(function () {
|
|
||||||
if (!this.files || !this.files.length) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (let i = 0; i < this.files.length; i++) {
|
|
||||||
totalBytes += this.files[i].size || 0;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return totalBytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
let ticket_id = $('#ticket_master_id').val();
|
let ticket_id = $('#ticket_master_id').val();
|
||||||
$('#ticket_id_url').val(ticket_id);
|
$('#ticket_id_url').val(ticket_id);
|
||||||
@ -218,9 +202,7 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const selectedPayloadBytes = getSelectedUploadPayloadSize();
|
if (typeof window.validateGlobalUploadPayload === 'function' && !window.validateGlobalUploadPayload(this)) {
|
||||||
if (selectedPayloadBytes > MAX_UPLOAD_PAYLOAD_BYTES) {
|
|
||||||
toastr.warning('Total selected file size must not exceed 25 MB.', 'Validation');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -257,7 +257,7 @@ input:checked + .slider:before {
|
|||||||
placeholder="Enter Client Name"
|
placeholder="Enter Client Name"
|
||||||
value="<?= isset($client['client_name']) ? $client['client_name'] : '' ?>" name="client_name"
|
value="<?= isset($client['client_name']) ? $client['client_name'] : '' ?>" name="client_name"
|
||||||
required maxlength="45" data-parsley-minlength="2" data-parsley-maxlength="45"
|
required maxlength="45" data-parsley-minlength="2" data-parsley-maxlength="45"
|
||||||
data-parsley-pattern="^[a-zA-Z0-9\\s_-]+$"
|
data-parsley-pattern="^[a-zA-Z0-9\s_-]+$"
|
||||||
data-parsley-pattern-message="Only letters, numbers, spaces, underscore (_) and hyphen (-) are allowed.">
|
data-parsley-pattern-message="Only letters, numbers, spaces, underscore (_) and hyphen (-) are allowed.">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group col-md-4">
|
<div class="form-group col-md-4">
|
||||||
|
|||||||
@ -263,7 +263,7 @@ input:checked + .slider-branch-contact:before {
|
|||||||
<label for="first_name">Name<span class="text-danger">*</span></label>
|
<label for="first_name">Name<span class="text-danger">*</span></label>
|
||||||
<input value="" type="text" class="form-control" placeholder="Enter Contact Name"
|
<input value="" type="text" class="form-control" placeholder="Enter Contact Name"
|
||||||
name="name[]" id="name" required
|
name="name[]" id="name" required
|
||||||
data-parsley-pattern="^[A-Za-z\\s]+$"
|
data-parsley-pattern="^[A-Za-z\s]+$"
|
||||||
data-parsley-pattern-message="Contact name may contain only letters and spaces.">
|
data-parsley-pattern-message="Contact name may contain only letters and spaces.">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group col-md-6">
|
<div class="form-group col-md-6">
|
||||||
@ -282,7 +282,7 @@ input:checked + .slider-branch-contact:before {
|
|||||||
<label for="last_name">Email<span class="text-danger">*</span></label>
|
<label for="last_name">Email<span class="text-danger">*</span></label>
|
||||||
<input value="" type="text" class="form-control" placeholder="Enter Contact Email"
|
<input value="" type="text" class="form-control" placeholder="Enter Contact Email"
|
||||||
name="email[]" id="email" data-parsley-trigger="change"
|
name="email[]" id="email" data-parsley-trigger="change"
|
||||||
data-parsley-pattern="^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$"
|
data-parsley-pattern="^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"
|
||||||
data-parsley-pattern-message="Please enter a valid email format (e.g., name@domain.com)."
|
data-parsley-pattern-message="Please enter a valid email format (e.g., name@domain.com)."
|
||||||
onchange="validateDuplicateByClientBranch(this, 'email','branchBtnSubmit')" required>
|
onchange="validateDuplicateByClientBranch(this, 'email','branchBtnSubmit')" required>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -274,6 +274,99 @@
|
|||||||
"closeButton": true,
|
"closeButton": true,
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
<script>
|
||||||
|
(function (window, document) {
|
||||||
|
var MAX_GLOBAL_UPLOAD_BYTES = 25 * 1024 * 1024; // 25 MB
|
||||||
|
|
||||||
|
function formatBytesToMb(bytes) {
|
||||||
|
return (bytes / (1024 * 1024)).toFixed(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getFilesSizeFromInput(input) {
|
||||||
|
if (!input || !input.files || !input.files.length) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
var total = 0;
|
||||||
|
for (var i = 0; i < input.files.length; i++) {
|
||||||
|
total += input.files[i].size || 0;
|
||||||
|
}
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getAllFileInputsScope(source) {
|
||||||
|
if (!source) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
if (source.matches && source.matches('form')) {
|
||||||
|
return source.querySelectorAll('input[type="file"]');
|
||||||
|
}
|
||||||
|
if (source.form) {
|
||||||
|
return source.form.querySelectorAll('input[type="file"]');
|
||||||
|
}
|
||||||
|
return document.querySelectorAll('input[type="file"]');
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTotalPayloadBytes(source) {
|
||||||
|
var inputs = getAllFileInputsScope(source);
|
||||||
|
var total = 0;
|
||||||
|
for (var i = 0; i < inputs.length; i++) {
|
||||||
|
total += getFilesSizeFromInput(inputs[i]);
|
||||||
|
}
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
|
function showGlobalFileWarning(message) {
|
||||||
|
if (window.toastr && typeof window.toastr.warning === 'function') {
|
||||||
|
window.toastr.warning(message, 'Validation');
|
||||||
|
} else {
|
||||||
|
window.alert(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function validateGlobalUploadPayload(source) {
|
||||||
|
var totalPayloadBytes = getTotalPayloadBytes(source);
|
||||||
|
if (totalPayloadBytes > MAX_GLOBAL_UPLOAD_BYTES) {
|
||||||
|
showGlobalFileWarning(
|
||||||
|
'Total selected file size is ' +
|
||||||
|
formatBytesToMb(totalPayloadBytes) +
|
||||||
|
' MB. Allowed maximum is 25 MB.'
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
window.validateGlobalUploadPayload = validateGlobalUploadPayload;
|
||||||
|
|
||||||
|
document.addEventListener('change', function (event) {
|
||||||
|
var target = event.target;
|
||||||
|
if (!target || !target.matches || !target.matches('input[type="file"]')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!validateGlobalUploadPayload(target)) {
|
||||||
|
target.value = '';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
document.addEventListener(
|
||||||
|
'submit',
|
||||||
|
function (event) {
|
||||||
|
var form = event.target;
|
||||||
|
if (!form || !form.matches || !form.matches('form')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!form.querySelector('input[type="file"]')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!validateGlobalUploadPayload(form)) {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
true
|
||||||
|
);
|
||||||
|
})(window, document);
|
||||||
|
</script>
|
||||||
<script>
|
<script>
|
||||||
window.__navPageName = "<?= esc($page_name ?? '') ?>";
|
window.__navPageName = "<?= esc($page_name ?? '') ?>";
|
||||||
window.__navUserName = "<?= esc(get_session_userdata()->first_name ?? 'NOT SET') ?>";
|
window.__navUserName = "<?= esc(get_session_userdata()->first_name ?? 'NOT SET') ?>";
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user