Expand my Community achievements bar.

AEM6.5 Adaptative form Dynamic validation on text field for guidefield component based on selection values

Avatar

Level 4

Hello,

 

I need to add Dynamic validation to /libs/fd/af/components/guidefield component.

 

It is dynamic because  for each selection value, I select there must be unique validation applied to guidefield component based on user input value to the field.

 

For example

 

Selection 1:   

A>guidefield  validation must be regex applied must be  AXXX-XXX4

B>The error displayed must be please enter in the format AXXX-XXX4

Selection 2  :

a>guidefield  validation must be regex applied must be  BXXX-XXXX-XXX9

B>The error displayed must be please enter in the format BXXX-XXXX-XXX9

 

could you please provide  inputs as how this could be  implemented and how to apply dynamic error messages.

 

Regards,

Srinivas

2 Replies

Avatar

Community Advisor

You need to use the switch block, something like below to achieve this,

 

let regexp, message;
switch (yourFormatType) {
case 'format1':
regexp = Format1_REGEXP;
message = 'The input is not a valid Format1';
break;
 
case 'format2':
default:
regexp = Format2_REGEXP;
message = 'The input is not a valid Format2';
break;
}

 

Avatar

Level 4

Thanks for the input.

 

My concern i am not able to Suppress default Validation error message in AEM

Srinivas_Opti_0-1679379624809.png

 

I would want to insert a error msg like 

 please enter in the format AXXX-XXX4, instead of OOTB msg "there is a validation error in the field" and also this will change for each selection.

 

How to achieve it 

 

Regards,

Srinivas