I am currently using Play Framework and was wondering if there is a helper template out there (even by a 3rd party) that will add the HTML5 attributes (e.g. required) based on the model annotations.
For example on my model
public class MyModel {
Constraints.Required(message="Required")
public String name;
}
on my View.Scala.html
@helper.inputText(
field = myModelForm("name"),
'_label -> "Name",
'_class -> "form-control",
'_showConstraints -> false,
'_showErrors -> true)
Is there an existing set of helper templates or 3rd party plugin that will add the required attribute on the HTML element?
I thought about creating my own helper templates but I'm not very familiar with Scala and do not know how to use reflection to check for attributes. If you are familiar with this syntax, please help! This would give me the flexibility to use Angular validation or jQuery validation but it's not a requirement at this point.
Thank you in advance!
There is a module for this: https://github.com/loicdescotte/Play2-HTML5Tags
I just tested it occasionally but seems it does what you need (at least with most popular constraints like Required
MinLength
etc. Also allows to use input fields with email
or number
type.
If it won't satisfy you I'm pretty sure that you can use it as reference and create custom solution.
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