is found it should just go to a noresults.aspx page.
I want the autocomplete's suggestion list to have it's data as listing of all the courses(child nodes of parent node
- Education). I am planning to create it as a macro so that I can use it on whichever template I want. Now the
autocomplete can accept its data source as a local array or even an external source. I haven't tried using the
external source yet but have tried using local data which I have hardcoded it as var pages = [ {text:'Education 1', url: '/education1.aspx'}, {text:'Education 2', url: '/education2.aspx'} ];
Now rather than hardcoding these values I need it to be more dynamic by picking the child nodes automatically. I'm
quite new to xslt and have no idea how to go about looping through the Education node and populate the autocomplete
with the array structure as above with 2 values the nodename and the niceurl link. Also the jquery autocomplete will
be initialized on the head section of the template like this:
Thanks for your response. Here is the final xslt I used. I decided to put the js within the body so that it only renders it when the search box is used on a template:
How to populate jquery autocomplete
Hi,
I have a node in the content tree called Educations. In this node we have all the types of educations listed as
child nodes. Now I simply need to create a search functionality on each page or on most pages. This search box does
not exactly function like a real search but rather it will be an autocomplete search box as a jquery plugin
(http://docs.jquery.com/Plugins/autocomplete). If a match is found it should go to the respective page, if no match
is found it should just go to a noresults.aspx page.
I want the autocomplete's suggestion list to have it's data as listing of all the courses(child nodes of parent node
- Education). I am planning to create it as a macro so that I can use it on whichever template I want. Now the
autocomplete can accept its data source as a local array or even an external source. I haven't tried using the
external source yet but have tried using local data which I have hardcoded it as
var pages = [ {text:'Education 1', url: '/education1.aspx'}, {text:'Education 2', url: '/education2.aspx'} ];
Now rather than hardcoding these values I need it to be more dynamic by picking the child nodes automatically. I'm
quite new to xslt and have no idea how to go about looping through the Education node and populate the autocomplete
with the array structure as above with 2 values the nodename and the niceurl link. Also the jquery autocomplete will
be initialized on the head section of the template like this:
$().ready(function() {
var pages = [ {text:'Education 1', url:'education1.aspx'}, {text:'Eduation 2', url: 'education2.aspx'} ];
$(".searchbox").autocomplete(pages, {
formatItem: function(data) { return data.text},
minChars: 3,
autoFill:true}).result(function(event, data) {
if (data != null)
{
window.location.href = data.url;
}
else
{
window.location.href = "noresults.aspx";
}
});
});
The above code seems self explanatory so won't go into details. So I simply need to populate the pages variable with
the values from the xslt. How do I go about doing that? The above code does not necessarily have to be in the head
section but I prefer putting it there. Otherwise if there is no other option the code could go into the xslt/macro.
Another question, can I have js embeded into my xslt and is it possible to put the js into the head section from the
xslt dynamically?
Wow I can't believe I have written all that text but the main point is how to populate the autocomplete with nodes
in xslt. The other option would be to use an ashx handler file to populate however not sure how to do that either.
Please if possible provide me with code for both the options xslt vs ashx.
Thanks,
Wasim
There are a couple of questions to answer, but I'll start with the easy one.
You can put your jquery in the head section no problem, and have the var pages populated by your macro like this:
As for the necessary xslt, you could do something like:
I don't think that xslt is perfect, so you'll have to do some tweaking. Hopefully it's enough to get you started!
Hi Lesley,
Thanks for your response. Here is the final xslt I used. I decided to put the js within the body so that it only renders it when the search box is used on a template:
is working on a reply...