From 5bcab5b7a5d6efe699b9ba79d03b77ec22ea59f4 Mon Sep 17 00:00:00 2001 From: venba-Inspriron-3558 Date: Wed, 15 Oct 2025 14:14:20 +0530 Subject: [PATCH] FIX_UI_support_Search_with_icon --- app/Views/leads_form_handler.php | 52 ++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/app/Views/leads_form_handler.php b/app/Views/leads_form_handler.php index cb17bb22..563c5933 100644 --- a/app/Views/leads_form_handler.php +++ b/app/Views/leads_form_handler.php @@ -452,6 +452,58 @@ if (isset($selected_lead_type)) { $('#salse_person_id').trigger('change'); } + // $('#client_name').on('input', generateShortName); + + let shortNameTimer; + + $('#client_name').on('input', function() { + clearTimeout(shortNameTimer); + shortNameTimer = setTimeout(generateShortName, 200); + }); + + function generateShortName() { + let clientInput = $("#client_name"); + let shortInput = $("#client_short_name"); + let newClientName = clientInput.val().trim(); + + console.log(`LN : NEW - ${newClientName}`); + if (newClientName.length == 0) { + shortInput.val(''); + return; + } + + let shortName = newClientName.substring(0, 10).replace(/\s+/g, '').toUpperCase(); + makeUniqueShortName(shortName); + } + + function makeUniqueShortName(baseName) { + let input = $("#client_short_name")[0]; + + checkDuplicateTableFieldValue("clients", "short_name", baseName, function(isDuplicate) { + if (isDuplicate) { + let counter = 1; + function tryNext() { + let padded = String(counter).padStart(3, '0'); // 001, 002, 003 + let newName = baseName + padded; + + checkDuplicateTableFieldValue("clients", "short_name", newName, function(exists) { + if (exists) { + counter++; + tryNext(); + } else { + $("#client_short_name").val(newName); + validateInput(input, "clients", "short_name"); + } + }); + } + tryNext(); + } else { + $("#client_short_name").val(baseName); + validateInput(input, "clients", "short_name"); + } + }); + } + function validateInput(input, table, field){ let client_type = $('#client_type').val();