Comments (9)
It's rather simple. Create a web service that expects to get a term to search and responds with possible matches for that term. In my own code I use JSON for the request and reply.
The web service, in my case, returns an array of possible matches in the format that is included in the hard coded example.
So all you need to do, once you have your web service done replace the hard coded block of autocomplete matches with an ajax call to the web service
callback: function( term, response )
{
ddt.log( "# callback with term '" + term + "'" );
// set up your ajax call here and send it the value of term in the request.
// you'll probably want to do it asynchronously so you'll set a success callback. which
// then forwards the results to autocomplete
// have your web service respond with a data structure that looks like the following:
[
{ label: 'tag1', value: { value: 'tag1', content: '<span class="ui-button ui-state-default ui-widget ui-corner-all ui-button-text-only">Tag1</span>' } },
{ label: 'tag2', value: { value: 'tag2', content: '<span class="ui-button ui-state-default ui-widget ui-corner-all ui-button-text-only">Tag2</span>' } },
{ label: 'tag3', value: { value: 'tag3', content: '<span class="ui-button ui-state-default ui-widget ui-corner-all ui-button-text-only">Tag3</span>' } },
{ label: 'tag4', value: { value: 'tag4', content: '<span class="ui-button ui-state-default ui-widget ui-corner-all ui-button-text-only">Tag4</span>' } }
]
// then in your success callback just feed the response and term back into the autocomplete.
response( $.ui.autocomplete.filter( tags, term ) );
}
from rich_textarea.
Thank you so much for your reply. I'm trying to implement your suggestion. I get the response from the web service (php) but I can't feed it back to the autocomplete.
callback: function( term, response )
{
console.log( "# callback with term '" + term + "'" );
$.ajax({
url: "path-to-the-php",
data: { term : term },
success: function(data)
{
var tags = data;
console.log(tags); /* see below */
response($.ui.autocomplete.filter(tags, term));
}
});
}
and this is the response I get
[ { label: 'tag1', value: { value: 'tag1', content: '<span>Tag1</span>' } },
{ label: 'tag2', value: { value: 'tag2', content: '<span>Tag2</span>' } },
{ label: 'tag3', value: { value: 'tag3', content: '<span>Tag3</span>' } },
{ label: 'tag4', value: { value: 'tag4', content: '<span>Tag4</span>' } } ]
Really suffering on this... :)
from rich_textarea.
This looks correct to me.
Are you getting any errors in the javascript error console?
What version of jQuery and jQuery UI are you using?
from rich_textarea.
Thank you for your response. jQuery and jQuery UI are the same as in your demo page.
Weird things going on... It works fine with this:
success: function(tags)
{
tags = ['tag1','tag2','tag3'];
response($.ui.autocomplete.filter(tags, term));
}
But is won't work with this:
success: function(tags)
{
response($.ui.autocomplete.filter(tags, term));
}
The only code in my web service php is this:
echo "['tag1','tag2','tag3']";
:'(
from rich_textarea.
check typeof( tags ). I bet you'll find that it's a string and not an object.
from rich_textarea.
You probably need to add dataType: 'json' to your ajax call.
from rich_textarea.
Ooooh Yermo! You rock! A simple eval
turned my misery into your magic! Thank you so much!
👍
from rich_textarea.
You're welcome. Let me know if you run into any problems. If your project is ever publicly visible I'd love to take a look at what you're working on.
from rich_textarea.
Will do. Thanks again!
from rich_textarea.
Related Issues (9)
- backspace to delete newline broken HOT 4
- _checkRegexes throws an undefined nodeValue exception on paste over selection.
- Question about insertObject HOT 3
- Converting [o={data-value}]? HOT 3
- NotFoundError: Failed to execute 'insertNode' on 'Range': The node provided is null HOT 7
- Up/Down arrow doesn't work in bootstrap modal HOT 11
- what is the best solution to indentity diffirent id type in value ? HOT 5
- Implement placeholder
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rich_textarea.