Hi @Gustav Sl ,
Welcome to the Microsoft Q&A Platform!
To prevent AzSearch.Automagic from automatically inserting a wildcard (*
) in the search box on page load, you can modify the initialization process of the search component. The behavior you're seeing typically happens because AzSearch.Automagic is designed to provide instant search functionality.
- Modify Initialization Parameters: Set the search initialization to avoid automatic querying and keep the search box empty:
var automagic = new AzSearch.Automagic({ query: '', // Ensures search box starts empty searchOnLoad: false, // Disables search execution on page load autoSearch: false // Prevents auto-search functionality });
- Programmatically Disable Auto-Search: Use the
setAutoSearch
method to ensure no searches are triggered automatically:javascriptautomagic.searchManager.setAutoSearch(false); // Disable any automatic search behavior
- Manually Trigger Search: Only trigger the search when the user enters a query:
document.getElementById('searchButton').addEventListener('click', function() { var query = automagic.searchBox.getValue(); if (query) { automagic.search(query); // Search triggered based on user input } });
- Review Configuration Files: Make sure no configuration file or fallback behavior is reintroducing the wildcard on page load.
- Override Search Box Behavior: Override the default method that retrieves the search box value to ensure it doesn't fall back to
*
:
By combining these methods, you should be able to prevent the wildcard character from being automatically inserted into the search box and ensure that no search is executed until the user manually enters a query.automagic.searchBox.getValue = function() { return ''; // Always returns an empty string unless a query is entered };
If the answer is helpful, please click "Accept Answer" and kindly upvote it.