Consider a blog with the entities Post and Author. There is a ManyToOne relation between Post and Author:
@Entity
public class Post extends Model {
@Required
public String subject;
@ManyToOne
@Required
public Author author;
//...
}
Then, in the view:
@form(routes.Post.new()) {
@inputText(postForm("subject"))
@select(
postForm("author.id"),
options(Author.options()),
'_label -> "Author",
'_default -> "-- Select author --",
'_showConstraints -> true
)
<input type="submit" value="Create" />
}
When validating this field using a Form<Post>
in a controller, the @Required constraint for the Author field is ignored when doing form.hasErrors().
How can I say that this field is required?