I understand how to add simple form validations in Play 2 such as nonEmptyText, but how would I implement more complex validations such as “at least one of the fields must be defined”? Presently I throw an exception in my model object if it gets initialized with all Nones, but this generates a nasty error message. I would prefer to get a friendly error message on the form page.
I understand how to add simple form validations in Play 2 such as nonEmptyText
Share
You can nest the
mappings/tuplesin your form definition and addverifyingrules on mapping, sub-mapping, tuple and sub-tuple.Then in your templates you can retrieve the errors using
form.errors("fieldname")for a specific field or a group a fields.For example :
If you have two different passwords, you can retrieve the error in your template using
form.errors("password")In this example, you will have to write your own
Account.applyandAccount.unapplyto handle(String, String, (String, String))