I've created form in play framework with constraints:
val voucherForm = Form(
mapping(
"voucherName" -> nonEmptyText,
"voucherCode" -> optional(text(minLength = 6).verifying(pattern("""[a-zA-Z0-9]+""".r, error = "...")))
)(VoucherForm.apply)(VoucherForm.unapply)
)
when I display this form on a web page I have constraint messages (like Required, Minimum length: 6, constraint.pattern) shown near input boxes.
I want to customise this constraint messages per input field (i.e. two nonEmptyText constraints in same form will have different constraint message). How could I do it?
Instead of using nonEmptyText, could you not use text, and put your custom message in the verifying, along the lines of:
val voucherForm = Form(
mapping(
"voucherName" -> text.verifying(
"Please specify a voucher name", f => f.trim!=""),
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With