Easily access and update your Excel spreadsheets, dashboards & financial models to optimize your workflows with a simple three-step installation that doesn’t require a technical team.
Why choose Preqin for Excel?
Quickly build formulas to update your financial models with the latest Preqin data with our powerful Formula Builder tool.
Ensure your reports use the latest data by instantly syncing Excel with your Preqin Saved Searches, Target Lists, and Custom Benchmarks with the Data Loader feature.
Leverage Preqin’s range of pre-built and fully customizable templates to save time and upgrade your Excel reports.
Work more securely and efficiently by eliminating time-consuming, error-prone manual updates when importing data into Excel.
Book your demo today to access the power of Preqin data directly from Excel.
'));
// Find the container (assuming it's the direct parent with the class)
const $container = $inputField.closest('#formField--companyName');
// Demo display element
const $idDisplaySpan = $('#selected-id-display span');
let $resultsContainer = null;
let $resultsList = null;
let valueWasSelected = false; // Flag to track if the current value is from selection
let responseData = null; // Store the response data
// --- Helper Functions ---
function ensureResultsListExists() {
if(!$resultsContainer || $resultsContainer.length === 0) {
$resultsContainer = $container.find('.autocomplete-results');
if($resultsContainer.length === 0) {
$resultsContainer = $('
');
$resultsContainer.append($resultsList);
}
}
}
$resultsList.empty();
return $resultsList;
}
function hideResults() {
if($resultsContainer && $resultsContainer.length) {
$resultsContainer.hide();
if($resultsList) {
$resultsList.empty();
}
}
if(currentRequest) {
currentRequest.abort();
currentRequest = null;
}
}
// Function to clear the stored ID
function clearSelectedId() {
$hiddenFirmIdInput.val('');
valueWasSelected = false;
$idDisplaySpan?.text('(None)'); // Update demo display
// console.log("Hidden ID cleared");
}
// Function to handle selection (from click or Enter key)
function handleSelection($selectedItem) {
if(!$selectedItem || $selectedItem.length === 0 || $selectedItem.hasClass('autocomplete-message')) {
return; // Do nothing if no valid item or it's a message
}
const selectedText = $selectedItem.text();
const selectedId = $selectedItem.data('company-id'); // Retrieve stored ID
if(selectedId) {
$inputField.val(selectedText); // Update visible input
$hiddenFirmIdInput.val(selectedId); // Update hidden input
valueWasSelected = true; // Mark that selection occurred
$idDisplaySpan?.text(selectedId); // Update demo display
// console.log("Selected:", selectedText, "ID:", selectedId);
hideResults();
$inputField.trigger('change'); // Optional: Trigger change event for other listeners
}
else {
console.warn('Selected item missing company ID data:', $selectedItem);
hideResults(); // Hide results even if ID is missing
}
}
// --- Event Handlers ---
$inputField.on('input', function() {
const currentInputValue = $(this).val();
const searchTerm = currentInputValue.trim();
// CRITICAL: If the user types anything, clear the previously selected ID
// Only clear if the flag 'valueWasSelected' is true, meaning the last change
// wasn't already a manual input modification.
if(valueWasSelected) {
clearSelectedId();
}
// We always set valueWasSelected to false here, because *any* input
// event means the current value is potentially manual, until a selection happens again.
valueWasSelected = false;
clearTimeout(debounceTimer);
if(currentRequest) {
currentRequest.abort();
currentRequest = null;
}
if(searchTerm.length === 0) {
hideResults();
clearSelectedId(); // Also clear ID if input is emptied
return;
}
debounceTimer = setTimeout(() => {
const $currentResultsList = ensureResultsListExists();
$currentResultsList.html('