Web page can't deal with junk entered into a date field

I created a simple web form with a simple date field. If someone enters junk into the date field, it throws up its hands and displays an error web page, loosing all previous input.

How can I create date fields that can gracefully display an error message, asking the user to correct the input? Do I need to change it from a date field to text?

Thanks for any advice. I’ll elaborate if it will help. I’m not trying to do anything too complex. In fact, I can recreate the problem with a form with one date field.

Subject: Nope, it’s always been this way.

“Unable to interpret time or date” is the error message. Entire page is hosed.

You get to roll your own JS for validation. And if your date/time format varies due to detecting the user’s web browser settings, you get to really have some fun.

XPages helps here. Hopefully you can replace your form with an XPage.

Subject: Two work arounds (not great, but …)

Thanks for the suggestions.

I don’t think javascript can help because I can’t handle the issue before Domino takes over.

I can change the field from type date to text, or I can make the field hidden and force users to use a calendar widget to select a date.

Not too crazy about either of those work arounds, but may be better than risk losing user input.

I don’t even know what X-pages are. :-). I guess I better get going.

Subject: javascript

Sure you can stop it before lotus gets it. Put the javascript in the onblur event, then if it’s an invalid date have it return the focus to the date field. That way the user can’t leave the date field until they fill out a proper date.

Subject: javascript

As you mention its a web database, I’d take a look at creating a javascript validation function to check its a valid format.

Subject: Example

An Example…function doValidDate(fld,opt)

{

err = 0;

var fval = fld.value;

if (opt == “O” && fval.length == 0 ) {

return 0;

}

if (opt == “M” && fval.length == 0 ) {

return -1;

}

if (fval.length != 10 ) {

err = 1;

}

else

{

if (fval.substr(2,1) != “/” || fval.substr(5,1) != “/” ) {

err = 2;

 }

else

 {  

   fnum = fval.substr(0,2) + fval.substr(3,2) + fval.substr(6,4);

   if (fnum.indexOf("/") > 0 )  {

     err = 3;

     }

   else

     {

       if (fnum.substr(0,1) < "0" || fnum.substr(0,1) > "9" || 

           fnum.substr(1,1) < "0" || fnum.substr(1,1) > "9" ||

           fnum.substr(2,1) < "0" || fnum.substr(2,1) > "9" ||

           fnum.substr(3,1) < "0" || fnum.substr(3,1) > "9" ||

           fnum.substr(4,1) < "0" || fnum.substr(4,1) > "9" ||

           fnum.substr(5,1) < "0" || fnum.substr(5,1) > "9" ||

           fnum.substr(6,1) < "0" || fnum.substr(6,1) > "9" ||

           fnum.substr(7,1) < "0" || fnum.substr(7,1) > "9" ) {

         err = 4;

          }

    }

}

}

// check the numeric value of days and months

if (err == 0) {

var dd = fval.substr(0,2);

var mm = fval.substr(3,2);

if (dd == 0 || mm == 0 || mm > 12 ||

 (dd > 31 && (mm == 01 || mm == 03 || mm == 05 || mm == 07 || mm == 08 || mm == 10 || mm == 12)) ||

 (dd > 30 && (mm == 04 || mm == 06 || mm == 09 || mm == 11)) ||

 (dd > 29 && (mm == 02)) )  {

    err = 5;

}

}

// check if the date is valid

if (err > 0) {

return -2;

}

return 0;

}

Subject: Thanks, Andrew. Good stuff, BUT …

I do have some javascript date validation code in place (posted below), but the error occurs before my javascipt validation code runs. Maybe I need to move the code to a different trigger/event.

Simple description of my problem:

I have a test form with two fields. One is a date field, the other is a radio button field with ‘refresh fields on keyword change’.

If I enter junk into the date field, then change the radio button value, the web form tries to refresh, but instead goes away completely and displays a generic message:

The website cannot display the page. HTTP 500. Most likely causes:

The website is under maintenance.

The website has a programming error.

In my opinion, this is horrible default behaviour by Domino. In my real life app, this means all of the user’s input is blown away.

Here is a code snippit of the date validation I have in place, triggered to run when someone submits a form:

//FlightDepartureDate required if Flight booking type - also make sure it is valid.

if(document.forms[0].FlightDepartureDate){

	if((document.forms[0].FlightDepartureDate.value.length < 1 | validateDate(document.forms[0].FlightDepartureDate, 'Flight Departure date') == false ) & document.forms[0].BookingTypeIncludesFlight.value.length > 2 ){

		msg +="\r - Flight Departure Date";

		msgflag="true";

		if(gotofield == ""){

		document.forms[0].FlightDepartureDate.focus();

		gotofield="FlightDepartureDate";

		}

}

}

/*********************************************************

validateDate()

This function checks to make sure the user has entered

a date.

Arguments:

fld = field

errMsg = english name of field for display on error

**********************************************************/

function validateDate(fld, errMsg)

{

var stDate = new Date(fld.value);

if (stDate == “NaN”)

{

//alert("Please enter a valid date for " + errMsg + “.”);

fld.focus();

return false;

}

return true;

}

Subject: BTW, is this new with 8.5?

I’ve been creating (admittedly simple) web apps in Domino for years (version 6.5 and older), and I don’t remember this ever happening before. It’s hard to believe Domino did not have a more graceful way of dealing with someone entering an invalid date in the past. I don’t have access to an older version of Domino to check.