View previous topic :: View next topic |
Author |
Message |
calendarxp Site Admin
Joined: 30 Jan 2005 Posts: 409
|
Posted: Tue Feb 15, 2005 7:40 pm Post subject: [PopCalendarXP]How to instantly validate the date keyed in by user? |
|
|
If you allow user to key in date string directly, you may want to validate it instantly. One consistent way is to use the built-in fParseInput() function of the calendar engine to do the job:
- create an onblur event handler on your <input> tag. e.g.
Code: | onblur="fValidate(this)". |
create the fValidate() function as following:
Code: | <script>
var invalidObj=true;
function fValidate(textbox) {
var dt=gfPop.fParseInput(textbox.value);
if (dt==null) {
invalidObj=textbox;
alert("Invalid date format!");
setTimeout("invalidObj.focus()", 50);
} else
invalidObj=null;
}
</script> |
hook the following onsubmit event trigger to your form tag:
Code: | <FORM name="demoform" onsubmit="return invalidObj==null;" ...> |
_________________ Copyright 2003-2011 Idemfactor Solutions, Inc. All rights reserved.
Last edited by calendarxp on Wed Jun 21, 2006 2:58 pm; edited 2 times in total |
|
Back to top |
|
|
cgarvey
Joined: 21 Nov 2005 Posts: 7
|
Posted: Wed Jun 21, 2006 1:47 pm Post subject: |
|
|
This isn't a very robust solution. The onblur event is fired when another element is clicked, but that other element could be a submit button.
How could you call an external validation method once the dateField has been populated with the selected value?
|
|
Back to top |
|
|
cgarvey
Joined: 21 Nov 2005 Posts: 7
|
Posted: Wed Jun 21, 2006 2:09 pm Post subject: |
|
|
Just had a look at the code and I think I could use the fAfterSelected function to call validation as well. What I need to know is the name of the handle to use for the input field so I do something like :
function fAfterSelected(y,m,d,e) {
if(dateFld.getAttribute('onChange')) eval(onChange);
}
I need to do this because although the onChange event is fired if the user enters a date manually, it isn't fired if the field is populated with calendarXP.
|
|
Back to top |
|
|
calendarxp Site Admin
Joined: 30 Jan 2005 Posts: 409
|
Posted: Wed Jun 21, 2006 2:53 pm Post subject: |
|
|
Well, you are right. Actually the title should be changed to "How to instantly validate the date keyed in by user?". And we just made some update to improve the situtation when submit button is pushed.
For your question, since the date format will always be valid when selected via the calendar, the only thing you may be interested is to do some post-processing, which we had it covered in the following FAQ:
http://calendarxp.net/forum/viewtopic.php?t=15
_________________ Copyright 2003-2011 Idemfactor Solutions, Inc. All rights reserved. |
|
Back to top |
|
|
calendarxp Site Admin
Joined: 30 Jan 2005 Posts: 409
|
Posted: Wed Jun 21, 2006 3:05 pm Post subject: |
|
|
For your 2nd question about triggering "onchange" on the input tag, you can actually use the built-in reference gdCtrl. Please refer to the following FAQ for a detailed explanation:
http://calendarxp.net/forum/viewtopic.php?t=30
_________________ Copyright 2003-2011 Idemfactor Solutions, Inc. All rights reserved.
Last edited by calendarxp on Wed Jun 21, 2006 3:10 pm; edited 1 time in total |
|
Back to top |
|
|
cgarvey
Joined: 21 Nov 2005 Posts: 7
|
Posted: Wed Jun 21, 2006 3:07 pm Post subject: |
|
|
gah...need to wake up
Quote: | if(gdCtrl.getAttribute('onchange')) gdCtrl.onchange(); |
works perfectly.
|
|
Back to top |
|
|
|