Im using this library for the first time, maybe Im making some stupid mistake but Im stuck.
I am using Play Framework 2.0 to serve regula 1.3.3 like this
<script src="@routes.Assets.versioned("javascripts/regula-1.3.3.js")" type="text/javascript"></script>
Then I have
<input type="text" name="age" id="age" data-constraints="@@Range(min=18, max=65)" />
Please Note that the @@ is required because of the Play Framework Template, however the Browser sees the same line like this:
<input type="text" name="age" id="age" data-constraints="@Range(min=18, max=65)">
and
$(document.body).on('change','input', function (event) {
var constraintViolations = regula.validate({
elements: [document.getElementById("age")]
});
});
On the Console:
Uncaught IllegalArgumentException: No constraints have been bound to the specified elements: age. Function received: {elements: [[object HTMLInputElement]], elementIds: [age]}
If I add another element:
<input type="text" name="email" id="email" value="@form("email").value" data-constraints='@@Email' >
and change the validation code to:
$(document.body).on('change','input', function (event) {
var constraintViolations = regula.validate({
elements: [document.getElementById("age"), document.getElementById("email")]
});
});
I get:
Uncaught TypeError: Cannot read property 'id' of null
I also tried calling regula.validate() whenever a input field changes but this simple returns a empty array every time.
What am I doing wrong?
Thanks for your help.