View previous topic :: View next topic |
Author |
Message |
PRANA
Joined: 10 Apr 2006 Posts: 6
|
Posted: Tue Apr 11, 2006 9:02 pm Post subject: Calendar Control and .Net Validators. |
|
|
Has anyone tried to use date picker in a .Net 1.1 application with a text box that also has required field validator? We are getting an error in ValidatorOnChange function of WebUIValidation.js file.
Thanks in advance for any help/suggestions.
|
|
Back to top |
|
|
calendarxp Site Admin
Joined: 30 Jan 2005 Posts: 409
|
Posted: Tue Apr 11, 2006 10:34 pm Post subject: |
|
|
It's because the calendar will trigger the onchange event using a javascript call while the client-side validator scripts assume the onchange event can only be triggered via a real user interaction - the major difference is that the event.srcElement of a script-triggered onchange will not be the desired input field.
To work around, we just need to patch the WebUIValidation.js file.
1st, find ValidatorOnChange function and replace it with following one:
Code: | function ValidatorOnChange(el) {
var vals = el.Validators;
var i;
for (i = 0; i < vals.length; i++) {
ValidatorValidate(vals[i]);
}
ValidatorUpdateIsValid();
} |
2nd, find the following string:
Code: | var func = new Function("ValidatorOnChange(); " + ev); | and replace it with
Code: | var func = new Function("ValidatorOnChange(this); " + ev); |
Now, the error should be gone.
_________________ Copyright 2003-2011 Idemfactor Solutions, Inc. All rights reserved. |
|
Back to top |
|
|
PRANA
Joined: 10 Apr 2006 Posts: 6
|
Posted: Tue Apr 11, 2006 11:00 pm Post subject: |
|
|
Thanks for the solution. It wroks and error is gone.
But we can not implement this solution since WebUIValidation.js file is shared by a number of applications on server. Changing this file means testing all the existing applications to make saure none of the validations are failing on IE and Netscape/Firefox.
Is there any solution that would require change(s) only in the files that render Calendar control, ex. ipopeng.htm?
Thanks!
|
|
Back to top |
|
|
calendarxp Site Admin
Joined: 30 Jan 2005 Posts: 409
|
Posted: Wed Apr 12, 2006 12:18 am Post subject: |
|
|
1st, this solution (patch) should work across browsers and shouldn't affect any existing application on your site. The original code in WebUIValidation.js is the one to be blamed, because it took a short-cut by using event.srcElement instead of passing in the element directly.
Of course, I fully understood your concern - so the next solution we could use is to disable one of the feature in PopCalendarXP so that it won't trigger the onchange event when a date is selected.
To disable this feature, simply make the following line the 1st line of the fAfterSelected() plugin function:
Code: | __isDateChange=false; |
This way the calendar will NOT fire the onchange event and therefore won't trigger the Validator scripts.
The downside is, obviously, that you lose the validation provided by ASP.NET if the date is picked via calendar. However, it may not be a big deal since the calendar always format the date in a desired way.
You can still keep the auto-post-back behavior of your page by adding the following line to the last line of fAfterSelected() plugin:
Code: | gdCtrl.form.submit(); |
Finally, please note that this issue is a common one to any date picker product, not just PopCalendarXP. It's really a bug, more or less, in the WebUIValidation.js of ASP.NET.
_________________ Copyright 2003-2011 Idemfactor Solutions, Inc. All rights reserved. |
|
Back to top |
|
|
chris_motch
Joined: 14 Mar 2006 Posts: 3
|
Posted: Wed Apr 12, 2006 12:59 pm Post subject: |
|
|
Just in case anyone else is looking at this. I'm using ASP.NET 2.0, and the solution above with the __isDateChange=false; is probably the best bet, reason being is with 2.0 there is no JS file so to speak, its a .axd file that I believe .NET generates on the fly etc.
|
|
Back to top |
|
|
PRANA
Joined: 10 Apr 2006 Posts: 6
|
Posted: Wed Apr 12, 2006 2:14 pm Post subject: |
|
|
Thanks for the second solution. It works beautifully.
Chris,
Thanks for confirming the solution!
|
|
Back to top |
|
|
calendarxp Site Admin
Joined: 30 Jan 2005 Posts: 409
|
Posted: Thu Apr 13, 2006 3:29 am Post subject: |
|
|
After further investigation on the behavior of ASP.NET, both 1.x and 2.0, we decided to remove the automatic triggering of onchange event when a date is picked.
Therefore, as from version 9.7.293 the issue should be gone no matter __isDateChange is set or not, because the calendar engine will not trigger the onchange event of the input field any more.
Of course, you may still enable it by yourself by adding the following code to the fAfterSelected plugin function:
Code: | if (gdCtrl.onchange) gdCtrl.onchange(); |
But you just have to remember to patch the client-side scripts generated by ASP.NET in order to avoid conflicts, as discussed before.
From our point of view, we really wish ASP.NET team could choose a right way to implement the Validator scripts so that the validation can be triggered via 3rd party scripts. However, it might just stay as a good wish.
_________________ Copyright 2003-2011 Idemfactor Solutions, Inc. All rights reserved. |
|
Back to top |
|
|
|