manhcodedao / jquery-watermark

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

Validate not working with watermark (i followed the instructions) #50

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
In IE8 and Firefox 3.6.13 (but not Chrome) I am calling watermark on a few 
fields then initialise jquery validate (in that order). For validators like 
'email' and 'url', validate is validating the watermark value.

I have checked and triple checked. Watermark is definitely called before the 
validate call.

I am using jQuery validate 1.7 and jQuery watermark 3.1.1.

Original issue reported on code.google.com by critchle...@gmail.com on 9 Feb 2011 at 4:46

GoogleCodeExporter commented 8 years ago
I'm calling watermark like this (if it matters):

if (jQuery.fn.watermark)
            form.find('.-w-wm').each(function () {
                $(this).watermark($(this).attr('title'), { className: '-w-watermark' });
            });

Original comment by critchle...@gmail.com on 9 Feb 2011 at 4:49

GoogleCodeExporter commented 8 years ago
If you would like to create a stripped-down test case page, I'll be happy to 
take a look.  Without that, I can't do much because I have been through this 
issue so many times, and each time there was something the person put on the 
page that caused a problem (not a problem with the Watermark plugin).

Original comment by t...@speednet.biz on 9 Feb 2011 at 2:30

GoogleCodeExporter commented 8 years ago
Thanks. I created another simple form and it is working. There appears to be 
something in my main form that is messing things up. I haven't been able to put 
my finger on it as yet though.

Original comment by critchle...@gmail.com on 9 Feb 2011 at 10:36

GoogleCodeExporter commented 8 years ago
You may want to make sure you're configuring the watermarks before the 
validations.  (Not just loading the scripts first)

Original comment by t...@speednet.biz on 9 Feb 2011 at 11:03

GoogleCodeExporter commented 8 years ago
Yeh i'm definately both loading the watermark script first and configuring it 
first. 

I had a look at what your was doing (hiding the watermarks and then showing 
them for the submit event) and realised I am manually triggering the validate 
in my code so that wouldn't work. Now i'm calling hideAll and showAll before 
and after respectively, the validate call. Maybe a note on this would be good 
on the home page - what to do if manually triggering jquery validate.

try {
            $.watermark.hideAll();
            if (currentScreen.length && form.valid && !form.valid())
                return;
        }
        finally {
            $.watermark.showAll();
        }

Original comment by critchle...@gmail.com on 9 Feb 2011 at 11:28

GoogleCodeExporter commented 8 years ago
There is already a note about what to do if you're manually triggering 
JavaScript events/code.

Original comment by t...@speednet.biz on 10 Feb 2011 at 12:01

GoogleCodeExporter commented 8 years ago
Really? I just searched for "event" and then for "hideAll". I didn't read 
anything that would lead me to think I should - call hideAll before 
programmatically calling validate. The section on Validate doesn't mention 
anything about that and seems geared towards users who are triggering the 
validation by the submit event of the form. The conclusion I drew was that by 
configuring watermarks before validation I had absolutely nothing else to worry 
about.

There's a lot of text there, apologies if I'm wrong... but I don't think I am.

Original comment by critchle...@gmail.com on 10 Feb 2011 at 4:15

GoogleCodeExporter commented 8 years ago
Again, if you're manually triggering things via JavaScript, you would obviously 
have to take care of the watermark.

Perhaps you should allow the validate plugin to use its default triggering 
method of relying upon the form's submit event.  If you did that, and if you 
followed the instructions for setting up the watermark before setting up the 
validation, the everything would work properly.

However, if you will not do that, then you need to do the hiding of the 
watermark yourself.

Original comment by t...@speednet.biz on 13 Feb 2011 at 5:27

GoogleCodeExporter commented 8 years ago
ASP.NET WebForms are problematic when it comes to using validate plugin's 
default onsubmit handler because you have multiple logical forms wrapped into 
one <form></form> which is why some my opt out to trigger validation manually.

Original comment by alkos333 on 4 May 2011 at 4:09

GoogleCodeExporter commented 8 years ago
I'm not sure what you mean by "which is why some my opt out to trigger 
validation manually."

I do ASP.NET validation myself with the watermark control on the page, and it 
works great for me.  Most problems are caused by minor javascript coding 
issues.  You basically should start by stripping out everything except the core 
functions, and then add things back in one-by-one until it fails.  Then you 
know the problem.

Original comment by t...@speednet.biz on 4 May 2011 at 5:49