CalendarXP.net Support Forum Index CalendarXP.net Support
Most forums here are private and invisible to public.
 
 FAQFAQ   SearchSearch   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[PopCalendarXP]How to instantly validate the date keyed in by user?

 
Post new topic   Reply to topic    CalendarXP.net Support Forum Index -> CalendarXP F.A.Q.
View previous topic :: View next topic  
Author Message
calendarxp
Site Admin


Joined: 30 Jan 2005
Posts: 409

PostPosted: Tue Feb 15, 2005 7:40 pm    Post subject: [PopCalendarXP]How to instantly validate the date keyed in by user? Reply with quote

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:

  1. create an onblur event handler on your <input> tag. e.g.
    Code:
    onblur="fValidate(this)".

  2. 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>

  3. 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
View user's profile Send private message
cgarvey



Joined: 21 Nov 2005
Posts: 7

PostPosted: Wed Jun 21, 2006 1:47 pm    Post subject: Reply with quote

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
View user's profile Send private message
cgarvey



Joined: 21 Nov 2005
Posts: 7

PostPosted: Wed Jun 21, 2006 2:09 pm    Post subject: Reply with quote

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
View user's profile Send private message
calendarxp
Site Admin


Joined: 30 Jan 2005
Posts: 409

PostPosted: Wed Jun 21, 2006 2:53 pm    Post subject: Reply with quote

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
View user's profile Send private message
calendarxp
Site Admin


Joined: 30 Jan 2005
Posts: 409

PostPosted: Wed Jun 21, 2006 3:05 pm    Post subject: Reply with quote

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
View user's profile Send private message
cgarvey



Joined: 21 Nov 2005
Posts: 7

PostPosted: Wed Jun 21, 2006 3:07 pm    Post subject: Reply with quote

gah...need to wake up

Quote:
if(gdCtrl.getAttribute('onchange')) gdCtrl.onchange();


works perfectly.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    CalendarXP.net Support Forum Index -> CalendarXP F.A.Q. All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


Copyright 2003- Idemfactor Solutions, Inc. All rights reserved.
Powered by phpBB © 2001, 2005 phpBB Group