Use autocomplete input on Play! views
For source parameter (view)
source: function( req, response ) {
$.getJSON( "@routes.Controller.auto("")" + extractLast( req.term ), { term: extractLast( req.term ) }, response );
}
On your controller class, create static method that accept the term: String parameter and return Json.
import org.codehaus.jackson.node.ObjectNode;
import play.libs.Json;
@BodyParser.Of(play.mvc.BodyParser.Json.class)
public static Result auto(String term) {
ObjectNode result = Json.newObject();
//populate with correct suggestions
return ok(result);
}
Written by Hendra Gunawan
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Jquery
Authors
Filed Under
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#