Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.
SOLVED

Force Feild upon Validation Error

Avatar

Level 4

I have a Date Field with the Validation Pattern date{MM/DD/YYYY}. Is there a way once the user get the error message the cursor goes back to the Date Field instead of going to the next field.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

You should be able to add the following JavaScript code to the exit event of the date field

if (this.formattedValue === this.rawValue)

{

    xfa.host.setFocus(this);

}

This works because the only time the formattedValue is the same as the rawValue is when then edit pattern validation fails (or when then edit pattern is YYYY-MM-DD ... the rawValue pattern).

Note: this goes against Adobe's  guidelines for designing forms, they reckon the user should be able to move though the form as they wish but there are a lot of real forms out there that work this way.

Regards

Bruce

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

Hi,

You should be able to add the following JavaScript code to the exit event of the date field

if (this.formattedValue === this.rawValue)

{

    xfa.host.setFocus(this);

}

This works because the only time the formattedValue is the same as the rawValue is when then edit pattern validation fails (or when then edit pattern is YYYY-MM-DD ... the rawValue pattern).

Note: this goes against Adobe's  guidelines for designing forms, they reckon the user should be able to move though the form as they wish but there are a lot of real forms out there that work this way.

Regards

Bruce

Avatar

Level 4

Thanks Bruce this worked great

Best regards

Parre