vivin / regula

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

Unbinding all constraints of an element #58

Closed oprichnik closed 10 years ago

oprichnik commented 10 years ago

Hi :)

I'm getting an exception ("Element with id " + id + " does not have any constraints bound to it)" when i want to unbind all constraints of an element in a form with multiple groups.

I looked at regula.js and in the "unbind" function, your are throwing an exception if your don't find at least one bound constraint to the given element in each group. The fact is that the element has for some groups any bound constraints..

Here is the code (regula.js:4986) :

if (typeof boundConstraints[group][id] !== "undefined") {
    delete boundConstraints[group][id];

    if (group !== "Default") {
        removeElementAndGroupFromBoundConstraintsIfEmpty(id, group);
    }
} else {
    throw new ExceptionService.Exception.IllegalArgumentException("Element with id " + id + " does not have any constraints bound to it. " + ExceptionService.explodeParameters(options));
}
vivin commented 10 years ago

So you have an element that has a constraint that belongs to multiple groups? How does the constraint definition look like, and can I see how you are calling unbind?

On Wed, Jan 22, 2014 at 1:39 AM, oprichnik notifications@github.com wrote:

Hi :)

I'm getting an exception ("Element with id " + id + " does not have any constraints bound to it)" when i want to unbind all constraints of an element in a form with multiple groups.

I looked at regula.js and in the "unbind" function, your are throwing an exception if your don't find at least one bound constraint to the given element in each group. The fact is that the element has for some groups any bound constraints..

Here is the code (regula.js:4986) :

if (typeof boundConstraints[group][id] !== "undefined") { delete boundConstraints[group][id];

if (group !== "Default") {
    removeElementAndGroupFromBoundConstraintsIfEmpty(id, group);
}

} else { throw new ExceptionService.Exception.IllegalArgumentException("Element with id " + id + " does not have any constraints bound to it. " + ExceptionService.explodeParameters(options)); }

— Reply to this email directly or view it on GitHubhttps://github.com/vivin/regula/issues/58 .

Ruin untold; And thine own sadness, Sing in the grass, When eve has forgot, that no more hear common things that gleam and pass; But seek alone to lip, sad Rose of love and ruin untold; And thine own mother Can know it as I know More than another What makes your own sadness, Set in her eyes.

$s="01:11:02:11:01:11:02:13:01:11:01:11:01:13:02:12:01:13:01:11: 04:11:06:12:04:11:01:12:01:13:02:12:01:14:01:13:01:11:03:12: 01:11:04:12:02:11:01:11:01:13:02:11:03:11:06:11:01:11:05:12: 02:11:01:11:01:13:02:11:02:12:01:12:04:11:06:12:01:11:04:12: 04:11:01:12:03:12:01:12:01:11:01:12:01:12:02:11:01:11:01:13: 02:11:01:02:11:01:12:02"; @a=split(/:/,$s);$j="";foreach$c(@a) {@n=split(//,$c);$j.=$n[0]x$n[1];} for($i=0;$i<$j=~y///c;$i+=8){print chr(unpack("N",pack("B32",substr("0"x32 .substr($j,$i,8),-32))));}

oprichnik commented 10 years ago

I have an element that has constraints for multiple groups, but not for all group.

Code to reproduce:

<html>
    <head>
        <script type="text/javascript" src="http://localhost/vivaweek_web/web/js/jquery.js"></script>
        <script type="text/javascript" src="http://localhost/vivaweek_web/web/js/regula-1.3.1-min.js"></script>
        <script type="text/javascript" src="http://localhost/vivaweek_web/web/js/jquery.regula.js"></script>
        <style type="text/css"></style>
    </head>
    <body>
        <input id="field1" type="text" data-constraints="@NotBlank(groups=[groupA, groupB])" />
        <input id="field2" type="text" data-constraints="@NotBlank(groups=[groupA])" />

        <script type="text/javascript">
            regula.bind();

            regula.unbind({elementId: 'field2'});
        </script>
    </body>
</html>
vivin commented 10 years ago

That is definitely a bug! Thank you for finding it. I thought I had fixed it, but apparently not. :) I will fix it along with a few other bugfixes for 1.3.3.

vivin commented 10 years ago

This issue is fixed now in the latest release. Thanks for reporting :)