loisoft / jquery-watermark

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

Does not hide watermark in ASP.NET MVC2 Ajax form #28

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Use Ajax.Form in ASP.NET MVC2, configure up jQuery Watermark for a text 
field.
2. hideAll is not called, and if I add one on "OnBegin" in the AjaxOptions then 
the watermark is removed, but the form is already serialized so the input 
fields contain the watermark values.

What is the expected output? What do you see instead?
Watermarks need to be removed prior to form serialization in 
Sys.Mvc.AsyncForm.handleSubmit.

What version of the product are you using? On what operating system?
3.0.6 with jQuery 1.4.1 on Win7/FF3.6

Original issue reported on code.google.com by ha...@active.com on 25 Jul 2010 at 9:53

GoogleCodeExporter commented 8 years ago
I hacked in a solution for my project where I learned from your trigger-code 
related to ASP.NET PageValidation and I added an override to 
Sys.Mvc.AsyncForm.handleSubmit. It's not 100% (I still have to set the 
watermarks again in Ajax.Form/OnSuccess and /OnFailure, but that may be 
possible to fix?) but works for me.

This is what I added to my code:
    $(document).ready(function () {
        setWatermark();    // my function that sets the watermark for this form

        var fn = window['Sys']['Mvc']['AsyncForm']['handleSubmit'];
        if (typeof (fn) === "function") {
            window['Sys']['Mvc']['AsyncForm']['handleSubmit'] = (function (origFn) {
                return function () {
                    $.watermark.hideAll();
                    return origFn.apply(null, Array.prototype.slice.call(arguments));
                };
            })(fn);
        }
    });

Original comment by ha...@active.com on 25 Jul 2010 at 10:37

GoogleCodeExporter commented 8 years ago
Is there a globally-scoped function that is called, which triggers the 
Sys.Mvc.AsyncForm.handleSubmit function call?

For example, in ASP.NET Web Forms, a call to __doPostback is made n the href of 
the link/button, and that triggers everything.

If there is a similar function call in MVC, perhaps you could add the function 
name to the triggerFns array near to top of the source file.

Also, if that's the case -- if there is such a function -- let me know and I 
can see if it would be appropriate to add it permanently to the triggerFns list.

Original comment by t...@speednet.biz on 27 Aug 2010 at 4:07

GoogleCodeExporter commented 8 years ago
I'm not sure how I can figure that out, sorry. I put a breakpoint in the 
handleSubmit but all I can see in the callstack is onsubmit, so I don't think 
there is a global function like that. It seems they are wiring it up on each 
form submit, but that's just my guess.

Original comment by ha...@active.com on 27 Aug 2010 at 6:24

GoogleCodeExporter commented 8 years ago
If you'd like, you can send me a demo page containing the problem and I'll take 
a look to figure out what's being called.

Original comment by t...@speednet.biz on 27 Aug 2010 at 6:40

GoogleCodeExporter commented 8 years ago
Just to clarify the above:  please send a LINK to a demo page.

Original comment by t...@speednet.biz on 27 Aug 2010 at 6:41

GoogleCodeExporter commented 8 years ago
http://abc123.is-a-geek.com
in the top-right box, click Logga in and the submit button there will do an 
ajax request where it happens. This URL is only temporarily.

Original comment by ha...@active.com on 27 Aug 2010 at 6:55

GoogleCodeExporter commented 8 years ago
Thanks for the link.  It looks like the issue is that the form tag is being 
created with an "onsubmit" attribute, and that is why it is able to occur 
before the watermark can intercept the submit event.

In MVC there should be a way to put a small piece of code in the form's 
onsubmit attribute BEFORE the MVC code executes.

BEFORE:

<form action="..." onsubmit="Sys.Mvc.AsyncForm.handleSubmit(this, new 
Sys.UI.DomEvent(event)...")

AFTER:

<form action="..." 
onsubmit="$.watermark.hideAll();Sys.Mvc.AsyncForm.handleSubmit(this, new 
Sys.UI.DomEvent(event)...")

I don't know of a way to intercept an onsubmit attribute placed in the HTML tag 
before it executes, so I think the above method may be your best approach.

Original comment by t...@speednet.biz on 28 Aug 2010 at 1:15

GoogleCodeExporter commented 8 years ago
Re-ordering of statements in page solves the perceived problem.

Original comment by t...@speednet.biz on 6 Sep 2010 at 12:10

GoogleCodeExporter commented 8 years ago
ok, I'll give that a try, thanks!

Original comment by ha...@active.com on 6 Sep 2010 at 7:11