type mismatch with @helper
-
12-12-2019 - |
Question
I'm trying to show a form with the values but it's not working.
my action:
public static Result login() {
User user = new User();
user.name = "Murilo";
Form<User> userForm = form(User.class);
return ok(login.render(userForm.fill(user)));
}
and my html:
@(myForm : play.data.Form[models.User])
<!DOCTYPE html>
<html>
<head>
</head>
<body>
@helper.inputText(myForm("name"))
</body>
</html>
but when I access it, the following error throws:
type mismatch; found : play.data.Form.Field required: play.api.data.Field
Solution
As a addition to nico_ekito's good answer: I usually do not use @helper..
because it is long and not/less readable if your form starts to grow (more fields). So I do the following:
@(editForm:Form[User]
@*** IMPORTS ****@
@import helper._
@form(routes.Tasks.save(), 'class -> "form-horizontal") {
@inputText(editForm:Form("description()").....)
@inputArea(editForm:Form("description()").....)
}
OTHER TIPS
In your template, it should be:
@(myForm : Form[User])
<!DOCTYPE html>
<html>
<head>
</head>
<body>
@helper.inputText(myForm("name"))
</body>
</html>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow