Home > widget-integration > InstantSearchService > validateWidgetData
InstantSearchService.validateWidgetData() method
Validate suggestion data before caching or rendering.
Extension point for TS teams to add custom validation rules. Return false to skip rendering and treat the response as empty.
Signature:
protected validateWidgetData(data: SuggestionResponse): boolean;
Parameters
|
Parameter |
Type |
Description |
|---|---|---|
|
data |
Raw suggestion response from the API |
Returns:
boolean
True if the data should be used, false to discard it
Example
window.boostWidgetIntegration.extend('InstantSearchService', (InstantSearchService) => {
return class CustomService extends InstantSearchService {
protected validateWidgetData(data) {
// Require at least one result type to be present
return (data.products?.length ?? 0) > 0 || (data.suggestions?.length ?? 0) > 0;
}
};
});