Community Search Panel – Custom Widget Not Triggering Navigation or Results
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Hi all,
I'm working on a custom version of the Community Search Panel widget in a Service Portal. The goal is to allow users to search posts within a specific community forum and remain on the same page with the relevant results. The problem is that after submitting the search, nothing happens, the page stays the same — no redirection or update to the search results. There are no console errors or warnings.
Any insight into making the navigation and data-binding work as expected would be greatly appreciated.
Client Script -
function($scope, $location, $rootScope) {
var c = this;
c.options.glyph = c.options.glyph || 'search';
c.options.title = c.options.title || c.data.searchMsg;
c.options.color = c.options.color || 'default';
c.items = [];
c.applycolor = false;
$scope.query = c.data.query;
// Sync search term when updated from another widget
$rootScope.$on('sp.search.refresh.searchterm', function(event, data) {
if (data?.keyword) {
$scope.query = data.keyword;
}
});
// Trigger search from another component
var searchCommunity = $rootScope.$on('sp.search.initiate.search', function(event, data) {
if (data?.keyword) {
executeSearch(data.keyword, data.type);
}
});
// Handle filter UI highlighting
var refreshSearchFilter = $rootScope.$on('sp.search.refresh.filter.pills', function(event, data) {
c.items = data || [];
c.applycolor = c.items.length > 0;
});
$rootScope.$on('sp.search.updated.filter.pills', function() {
c.applycolor = false;
});
// Handle search submission
c.onSubmit = function(e) {
if (!$scope.query) {
e.preventDefault();
return;
}
$scope.$broadcast('logSearch', {
query: $scope.query,
url: $location.url(),
page: $location.search().id
});
var item = { query: $scope.query };
$rootScope.$emit('sp.search.updated.searchterm', item);
};
// Toggle filter/facet pane
c.toggleFacets = function() {
$rootScope.showFacet = !$rootScope.showFacet;
};
// Determine mobile view
var isMobileWidth = $(window).width() <= 992;
$rootScope.isMobile = isMobileWidth;
if (!isMobileWidth) {
$rootScope.showFacet = false;
}
// Cleanup
$scope.$on('$destroy', function() {
refreshSearchFilter();
searchCommunity();
});
// Internal search routing
function executeSearch(term, type) {
if (!term) return;
var sysId = $location.search().sys_id;
var searchData = {
id: 'forum_posts',
q: term,
t: type,
spa: '1',
forums: sysId,
sys_id: sysId
};
if ($rootScope.variableParams) {
for (let key in $rootScope.variableParams) {
searchData[key] = $rootScope.variableParams[key];
}
}
$location.url('?id=forum_posts&' + $.param(searchData));
}
// Ask question redirection config
var meta = { backUrl: $location.url() };
var secretQuery = window.csm_util
? csm_util.enigmia.encode(JSON.stringify(meta))
: encodeURIComponent(JSON.stringify(meta));
c.redirectConfig = {
redirectToUrl: `?id=community_ask_question&v=page&metadata=${secretQuery}&suggest=1`,
isLoggedIn: c.data.isLoggedIn,
loginUrl: ''
};
}
Thanks in advance!
