Last Updated: February 25, 2016
·
1.944K
· drabiter

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);
}

More.