Expand my Community achievements bar.

SOLVED

DateTime field validation (without custom handling functions)

Avatar

Level 3

Hello

I need to know how I can validate if a date is correct or not, and on failure to do something.

I have a DateTime Field field, with a pattern 'DD / MM / YYYY', the value is correctly displayed using the chosen pattern, the problem is validation.


Now I just want that if the date is wrong, teaches an alert to the user, and the focus returns to the DateTime control until you enter a valid value.

I need something like:

- Form1.SUBVENCION_O_AYUDA.dateTimeField1:: validate - (JavaScript, client) --

if (this.rawValue! = null && !test(this.rawValue, 'DD/MM/YYYY')) {

xfa.host.setFocus("this");
}

How do I know if the validation is successful or not (without having to implement long date handling functions)?

By default, if I set "validation pattern messaga" to field, a warning message is shown, but here the focus is lost and the user can continue filling the rest of the form, while the datetime field is filled with an incorrect value.

I want to prevent the user to continue filling the form if the dateTime field value is invalid.

Any idea?

Thank you!

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

If your date can not be formatted correctly against your display pattern then the fields formattedValue will equal the rawValue.

So in the exit event put;

if (this.rawValue == this.formattedValue)

{

     app.alert("Enter a date in 'dd / mm / yyyy' format");

     xfa.host.setFocus(this.somExpression);

}

Bruce

View solution in original post

1 Reply

Avatar

Correct answer by
Level 10

Hi,

If your date can not be formatted correctly against your display pattern then the fields formattedValue will equal the rawValue.

So in the exit event put;

if (this.rawValue == this.formattedValue)

{

     app.alert("Enter a date in 'dd / mm / yyyy' format");

     xfa.host.setFocus(this.somExpression);

}

Bruce