Play Framework 2 Limits Client Side Validation

I am currently using the Play Framework and wondering if there is an auxiliary template (even a third-party one) that will add HTML5 attributes (for example, the necessary ones) 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 a third-party plugin that will add the required attribute to the HTML element?

I was thinking of creating my own helper templates, but I am not very familiar with Scala and do not know how to use reflection to check attributes. If you are familiar with this syntax, please help! This would give me the flexibility to use Angular validation or jQuery validation, but this is not a requirement at the moment.

Thank you in advance!

+6
source share
1 answer

There is a module for this: https://github.com/loicdescotte/Play2-HTML5Tags

I just tested this from time to time, but it seems like it does what you need (at least with most of the popular restrictions, such as Required MinLength , etc. It also allows you to use input fields of type email or number .

If this does not suit you, I am sure that you can use it as a reference and create your own solution.

+4
source

Source: https://habr.com/ru/post/985911/


All Articles