So, let's say I have a webapp that allows users to save their hobbies. So I have a view like this:
class Hobby(ndb.Model): hobby_name = ndb.StringProperty()
Users simply create Hobby objects using this form:
<form action="/new-hobby" method="post"> <input type="text" name="hobby_name" id="new-hobby" /> <input type="submit" value="Save New Hobby" /> </form>
Then this form is processed as follows:
# Handles /new-hobby class NewHobby(webapp2.RequestHandler): def post(self): hobby_name = self.request.get('hobby_name') if hobby_name: h = Hobby(hobby_name = hobby) h.put() app = webapp2.WSGIApplication([ ('/new-hobby/?', NewHobby) ], debug=True)
This is standard material. With this setting, users can be seen in the same hobby in different ways (for example: “basketball”, you can enter “basketball”). Here, autocomplete functionality will be useful, increasing the "unified" input of all users.
So, I decided to use the Jquery Multiselect Remote Autocomplete Widget ( http://jqueryui.com/autocomplete/#multiple-remote ):
<script> $(function() { function split( val ) { return val.split( /,\s*/ ); } function extractLast( term ) { return split( term ).pop(); } $( "#birds" ) .bind( "keydown", function( event ) { if ( event.keyCode === $.ui.keyCode.TAB && $( this ).autocomplete( "instance" ).menu.active ) { event.preventDefault(); } }) .autocomplete({ source: function( request, response ) { $.getJSON( "search.php", { term: extractLast( request.term ) }, response ); }, search: function() { var term = extractLast( this.value ); if ( term.length < 2 ) { return false; } }, focus: function() { return false; }, select: function( event, ui ) { var terms = split( this.value ); terms.pop(); </script>
The remote source is indicated above in the line $.getJSON( "search.php",...); .
So, assuming that I am on the right track, the question arises: what file should I replace search.php , and what should be inside this file?