Expand my Community achievements bar.

SOLVED

Delte the value after validation fails

Avatar

Level 4

I've got some date and time fields in my form.

Since users tended to ignore the error of the validation message they got and the data that was overgiven was wrong too, I want to delte the fieldinput if the validation has failed.

Has anyone a script by his hand?

Thanx already for looking here

Lisa

PS.: A user can easily fill out a datefield with the calender... isn't there something similar for a timefield to show him in which format he has to enter the time?

1 Accepted Solution

Avatar

Correct answer by
Level 4

Just a little correction to the leap year condiction.

It should be something like ((YYYY%4 == 0 && YYYY%100!=0) || YYYY%400==0).

If you can, post the current version of your form so we can look at it please.

View solution in original post

5 Replies

Avatar

Former Community Member

Hi,

   I guess this script should work:

In the validation event:

If ( Field1.validate.scriptTest = "error" ) then

Field1.rawvalue = "".

We can use warning/disabled instead of error depending on the validation you would like to us.

Regards,

kc

Avatar

Level 4

Didn't work... (checked quite a number of similar scripts, I could imagine would work)

It should be a normal date/time validation like it does on pattern... (I did it like that, though these won't delte the wrong entry.)

(We had users that have written in date: "yesterday" and in time: "at night". And when they got error messages they simply ignored them.

The error messages are all right, since they tell the user he has done something invalid.


Little thought: isn't it possible to do it not via patterns but regular expressions?)

Avatar

Level 4

Can anyone help?

I tried to achieve my goal using older scripts I found...

Both scripts I wanted to use are out of older threads and (at least one) was thought for something else.

But I can't get them to work. Does anyone have any suggestions?

First I want to check if the format is correct.

1. Script, that should avoid characters that don't belong in there:

var r = new RegExp("[0-9]{2}+\\.[0-9]{2}+\\.[0-9]{4}$");

var result = r.test(this.rawValue);

if (result == true)
    {true;}           
else               
    {false; this.rawValue = null;}

2. Script that should check if the date does really exist:

var DD = parseFloat(this.formattedValue.substr(0,2)); //get days

var MM = parseFloat(this.formattedValue.substr(3,2)); // get month

var YYYY = parseFloat(this.formattedValue.substr(6,4)); // get year


if(DD > 31 || DD < 1) //simple check if Days are in the range

{this.rawValue = null;}

if (MM > 12 || < 1) //check if month are in the range

{this.rawValue = null;}

if ((MM == 4 || MM == 6 || MM == 9 || MM == 11) && DD > 30)    // check if the 30 days month won't have 31 days

{this.rawValue = null;}

if (MM == 2 && YYYY%4 == 0 && DD > 29) // check february if it's a leap year

{this.rawValue = null;}

if (MM == 2 && YYYY%4 != 0 && DD > 28) // check february in a normal year

{this.rawValue = null;}

Avatar

Correct answer by
Level 4

Just a little correction to the leap year condiction.

It should be something like ((YYYY%4 == 0 && YYYY%100!=0) || YYYY%400==0).

If you can, post the current version of your form so we can look at it please.

Avatar

Level 4

Good remark

Though, I think they won't use this form in 100 years still. ^^

Well I'll change it though

Here's the examplesheet.

If it's queued you can send me a private message with your mail and I'll send it.

Thanks for your help

PS:Regular Expression does now work.

var r = new RegExp("[0-9]{4}\\-[0-9]{2}\\-[0-9]{2}$");

Now I just need an expression for time...

var r = new RegExp("[0-9]{1,2}\\:[0-9]{0,1,2}\\:[0-9]{0,1,2}$") doesn't work...