nanatiris / jquery-watermark

Automatically exported from code.google.com/p/jquery-watermark
0 stars 0 forks source link

ASP.NET ValidationGroup bug #11

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.Create blank aspx page, place this inside form1
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <asp:LinkButton ID="LinkButton1" ValidationGroup="test1"
runat="server">LinkButton</asp:LinkButton>
            <asp:CustomValidator ID="CustomValidator1" ValidationGroup="test1"
runat="server" ClientValidationFunction="validateRequired"
ErrorMessage="CustomValidator1" ControlToValidate="TextBox1"
ValidateEmptyText="True"></asp:CustomValidator>
            <br />
            <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
            <asp:LinkButton ID="LinkButton2" ValidationGroup="test2"
runat="server">LinkButton2</asp:LinkButton>
            <asp:CustomValidator ID="CustomValidator2" ValidationGroup="test2"
runat="server" ClientValidationFunction="validateRequired"
ErrorMessage="CustomValidator2" ControlToValidate="TextBox2"
ValidateEmptyText="True"></asp:CustomValidator>

2. Place this script between head and body
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">     google.load("jquery", "1.3.2");</script>
<script type="text/javascript">
    function validateRequired(oSrc, args) {
        var txt = $get(oSrc.controltovalidate);
        var pass = (args.Value.length > 0);
        if (pass) {
            $('#' + txt.id).removeClass('requirederror');
            args.IsValid = true;
        }
        else {
            // set length css class to error.
            $('#' + txt.id).addClass('requirederror');
            args.IsValid = false;
        }
    }
</script>

When you click on first link, only 1 validator execute, when you click on
second link another textbox validate. It happened, because i separate them
by ValidationGroup. It works as expected.

Now add between header and body
<script type="text/javascript" src="jquery.watermark.js"></script>

And now when you click on any linkbutton validation happened for all
controls. Which not suppose to be. Is any way to fix it. I dont use
watermark library on my page, but its in Master page.Im using Nov 11 release.
Thanks a lot for great product

Original issue reported on code.google.com by gera...@gmail.com on 24 Nov 2009 at 9:47

GoogleCodeExporter commented 9 years ago
Here is a fix:
// Hijack any functions found in the triggerFns list
if (triggerFns.length) {

    // Wait until DOM is ready before searching
    $(function () {
        var i, name, fn;

        for (i=triggerFns.length-1; i>=0; i--) {
            name = triggerFns[i];
            fn = window[name];

            if (typeof(fn) === "function") {
                window[name] = (function (origFn) {
                    return function () {                    $.watermark.hideAll();
//HERE IS A FIX
if (arguments.length == 1) origFn(arguments[0]) else orifFn();
                    };
                })(fn);
            }
        }
    });
}

Original comment by gera...@gmail.com on 24 Nov 2009 at 11:31

GoogleCodeExporter commented 9 years ago
Can you try inserting a different fix to see if it works in your scenario?

Please replace the line you marked "HERE IS A FIX" (the if/else) with the 
following: 
line of code.  It is more generic, and should work with all functions.

origFn.apply(null, Array.prototype.slice.call(arguments));

Original comment by t...@speednet.biz on 30 Nov 2009 at 5:00

GoogleCodeExporter commented 9 years ago
Yes it works, tried couple of different scenarios.
Thanks for great product.

Original comment by gera...@gmail.com on 30 Nov 2009 at 5:46

GoogleCodeExporter commented 9 years ago
Awesome, thanks for testing, I'll make it part of the next release.  Thanks for 
the 
props too.

Original comment by t...@speednet.biz on 30 Nov 2009 at 10:23

GoogleCodeExporter commented 9 years ago
BTW, one small thing you (and anyone!) can do to help is to give the plugin a 
rating 
over at the jQuery site:  http://plugins.jquery.com/project/jquery-watermark

Thanks!

Original comment by t...@speednet.biz on 30 Nov 2009 at 10:25

GoogleCodeExporter commented 9 years ago
FIXED in version 3.0.3

Original comment by t...@speednet.biz on 1 Dec 2009 at 1:23