Last Updated: February 25, 2016
·
2.445K
· 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.

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
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