vivin / regula

Regula: An annotation-based form-validation framework in Javascript
126 stars 24 forks source link

Fixes for issues #8 & #10 #12

Closed troyji closed 13 years ago

troyji commented 13 years ago

Fix for issue #10: https://github.com/vivin/regula/issues/10 Fix for issue #8: https://github.com/vivin/regula/issues/8

troyji commented 13 years ago

All of the test cases pass on the included change sets.

Additionally, I ran a few more tests with these changes on a test site. They are working beautifully.

The following tests require 'jquery.js' and 'regula.js'.

troy.html

<html>
  <body>
    <input type="text" data-constraints="@IsNumeric"></input>
    <div id="content">
      <input type="text" data-constraints="@Required"></input>
    </div>
    <button id="validate">Validate</button>
    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript" src="regula.js"></script>
    <script type="text/javascript" src="troy.js"></script>
  </body>
</html>

troy.js

$(window).load(
  function()
  {
    $("#validate").click(function()
    {
      regula.bind();
      $("#content").remove("*");
      var results = regula.validate();
      $.each(results, function(i, r)
      {
        alert(r.message);
      });
    });
  });

Note that the input elements do not use the 'regula-validation' class. Note that the input box inside of the 'content' div is being destroyed between calls to 'bind()' and 'validate()'.