Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events
SOLVED

How to validate a drop-down list before move on?

Avatar

Former Community Member

Hello,

I want to force the user to select a value in the drop-down list before she can move on the the next  field.  for instances, I have a drop-down list A, whose default value is empty.  as the user clicks on the next field, I need to throw a warning that she needs to select the value for drop-down list A.

Thank you for your help.

1 Accepted Solution

Avatar

Correct answer by
Level 5

Yeah it would be the same idea basically. But you just need to decide where to have the event (on enter/ on exit of which field) and then use the same code where you can as many conditions as you like. For example,

if ( field1.isNull && dropdown1.isNull )

{

...

}

and so on.

View solution in original post

4 Replies

Avatar

Level 5

On the exit event of the drop-down list, you can do a test

if ( this.isNull )

{

    xfa.host.messageBox("Select item from list");

}

You can place any other custom changes to the field inside the if statement to show the error.

Avatar

Former Community Member

Hi,

Thank you.  It looks like this only validate when I click on the field without entering/selecting then move on.  Is there a way I can validate the field in a way that if I have field 1/dropdown1, then field 2/dropdown 2.  If I click on field 2, there is a message popup saying that 'field 1/dropdown 1 can't be empty.  Please make your selection before move on'.

Thanks.

Avatar

Correct answer by
Level 5

Yeah it would be the same idea basically. But you just need to decide where to have the event (on enter/ on exit of which field) and then use the same code where you can as many conditions as you like. For example,

if ( field1.isNull && dropdown1.isNull )

{

...

}

and so on.