FIX_resolved - Email duplication based on ClientBrach testcase wise.
This commit is contained in:
parent
4eccdbdcec
commit
3c1eb1bbc4
@ -956,55 +956,108 @@ function validateDuplicateByClientBranch(input, field, submitButId) {
|
||||
let message = label ? label + " is duplicate!" : "Value is duplicate!";
|
||||
|
||||
console.log(`cId: ${clientId} | bId: ${branchId}`);
|
||||
|
||||
|
||||
// Don't forgot be careful
|
||||
// 1 Local duplication check (User entered)
|
||||
let isLocalDuplicate = false;
|
||||
$('input[name="' + field + '[]"]').each(function(index) {
|
||||
let compareVal = $(this).val().trim();
|
||||
console.log(`Entered value: ${value} | Contact ${index+1} value: ${$(this).val()}`);
|
||||
if (this !== input && $(this).val().trim() === value) {
|
||||
if (this !== input && compareVal !== '' && compareVal === value) {
|
||||
isLocalDuplicate = true;
|
||||
return false; // break loop
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
if (isLocalDuplicate) {
|
||||
console.log(`r u n Local`);
|
||||
console.log(`btn Dis - true`);
|
||||
console.log(`duplicate found for ${field}`);
|
||||
toastr.warning(message, 'WARNING');
|
||||
$('#' + submitButId).prop('disabled', true);
|
||||
return; // don’t call server if duplicate in UI
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// important Skip empty values
|
||||
if (value === '') {
|
||||
checkAllFieldsValid(submitButId);
|
||||
return;
|
||||
}
|
||||
|
||||
// Don't forgot be careful
|
||||
// 2 Server-side duplicate check (DB)
|
||||
if (!isLocalDuplicate && value !== '') {
|
||||
|
||||
$.ajax({
|
||||
url: '<?= base_url("client/others/check-duplicate") ?>',
|
||||
type: 'POST',
|
||||
data: {
|
||||
client_id: clientId,
|
||||
branch_id: branchId,
|
||||
value: value,
|
||||
field: field
|
||||
},
|
||||
dataType: 'json',
|
||||
success: function(response) {
|
||||
if (response.isDuplicate) {
|
||||
console.log(`r u n Server`);
|
||||
console.log(`btn Dis - true`);
|
||||
toastr.warning(message, 'WARNING');
|
||||
$('#' + submitButId).prop('disabled', true);
|
||||
} else {
|
||||
console.log(`btn Dis - false`);
|
||||
$('#' + submitButId).prop('disabled', false);
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('AJAX Error:', error);
|
||||
$.ajax({
|
||||
url: '<?= base_url("client/others/check-duplicate") ?>',
|
||||
type: 'POST',
|
||||
data: {
|
||||
client_id: clientId,
|
||||
branch_id: branchId,
|
||||
value: value,
|
||||
field: field
|
||||
},
|
||||
dataType: 'json',
|
||||
success: function(response) {
|
||||
if (response.isDuplicate) {
|
||||
console.log(`r u n Server`);
|
||||
console.log(`duplicate found for ${field}`);
|
||||
toastr.warning(message, 'WARNING');
|
||||
$('#' + submitButId).prop('disabled', true);
|
||||
} else {
|
||||
console.log(`No duplicate for ${field}`);
|
||||
checkAllFieldsValid(submitButId);
|
||||
}
|
||||
});
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('AJAX Error:', error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// recheck all contacts before enabling submit
|
||||
function checkAllFieldsValid(submitButId) {
|
||||
let emailDuplicates = false;
|
||||
let mobileDuplicates = false;
|
||||
|
||||
// cross check all EMAIL duplicates
|
||||
let emailSeen = [];
|
||||
$('input[name="email[]"]').each(function() {
|
||||
let val = $(this).val().trim();
|
||||
if (val && emailSeen.includes(val)) {
|
||||
emailDuplicates = true;
|
||||
} else if (val) {
|
||||
emailSeen.push(val);
|
||||
}
|
||||
});
|
||||
|
||||
// cross check all MOBILE duplicates
|
||||
let mobileSeen = [];
|
||||
$('input[name="mobile[]"]').each(function() {
|
||||
let val = $(this).val().trim();
|
||||
if (val && mobileSeen.includes(val)) {
|
||||
mobileDuplicates = true;
|
||||
} else if (val) {
|
||||
mobileSeen.push(val);
|
||||
}
|
||||
});
|
||||
|
||||
if (emailDuplicates || mobileDuplicates) {
|
||||
$('#' + submitButId).prop('disabled', true);
|
||||
// show correct message based on what’s duplicated
|
||||
if (emailDuplicates && mobileDuplicates) {
|
||||
toastr.warning("Email and Mobile values are duplicate!", "WARNING");
|
||||
console.log('Both Email and Mobile duplicates');
|
||||
} else if (emailDuplicates) {
|
||||
toastr.warning("Email duplicate!", "WARNING");
|
||||
console.log('Cross Check Email duplicates');
|
||||
} else if (mobileDuplicates) {
|
||||
toastr.warning("Mobile duplicate!", "WARNING");
|
||||
console.log('Cross Check Mobile duplicates');
|
||||
}
|
||||
console.log(`btn Dis - true`);
|
||||
} else {
|
||||
console.log('unique — enable');
|
||||
console.log(`btn Dis - false`);
|
||||
$('#' + submitButId).prop('disabled', false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user