vivin/regula

regula-1.3.1-min.js not working as expected.

bythewiseman opened this issue · 9 comments

This doesn't seem to work properly.

Add html element:

<input type="text" data-constraints="@Required" class="regula-validation" id="test" />
<input type="button" class="next" id="btnDetails" />

Add link to code:

<script src="/common/javascript/regula-1.3.1-min.js" type="text/javascript"></script>

Add javascript code:

$(document).ready(function () {

regula.bind(); 

$(".next").click(function (e) {

            e.preventDefault();

            var constraintViolations = regula.validate();
            alert(constraintViolations.length);
            for (var i = 0; i < constraintViolations.length; i++) {
                var constraintViolation = constraintViolations[i];

                for (var j = 0; j < constraintViolation.failingElements.length; j++) {
                    //Assuming the browser supports 'setCustomValidity'; otherwise you will have to render
                    //the errors in some other manner
                    constraintViolation.failingElements[j].setCustomValidity(constraintViolation.message);
                    alert("fail");
                }
            }

        });

}

This returns 0 constraint errors.

When I change the link to the minified code to:

<script src="/common/javascript/regula-1.3.1.js" type="text/javascript"></script>

It works as expected - 1 error when nothing in the code. Am I missing something?

Interesting. Do you see anything in the console? Any JavaScript errors?

In Chrome 32.0.1700.76 m I get : Uncaught TypeError: Cannot read property 'mozilla' of undefined, jquery-ui.js : 10
In FF 26.0 : c.browser is undefined. jquery-us.js line 10.

But I get those errors no matter the version of the code I use.

jQuery : //code.jquery.com/jquery-1.10.2.min.js
jQuery UI 1.7.3

Created a completely clean HTML page and it still didn't work.

I don't use jQuery-UI in my project so that's strange that this should be showing up. Let me take a look at this to see if I can duplicate it. Hopefully I am able to do it after work today.

No, it's my project that has jQuery UI in it. But the plain HTML page without jQuery UI doesn't work either with the min file.

Checked this out and it looks like this is a legitimate issue with the minified version. During minification, something is changing. I will take a closer look at this.

So it looks like the Closure compiler was to blame. I didn't go look into it too much, but it looks like some aggressive optimizations were made, which rendered some of the code non-functional. I've change it to simply use the default r.js optimizer. Will update the release soon. Thanks for alerting me to this!

Updated 1.3.1 release to use default optimizer instead of Closure.

Thank you for this quick turn around. Your validator is awesome and clean and simple!! Love it.

No problem! Thank you for finding the issue :)