Required Fields and Dropdown Help in AEM as Cloud | Community
Skip to main content
March 7, 2023
Solved

Required Fields and Dropdown Help in AEM as Cloud

  • March 7, 2023
  • 4 replies
  • 1746 views

Hi,

I am using dropdown field with show/hide property which has four values and it will populate different set of required field items based upon the selection.So, when i author and try to save any one of the dropdown items , it throws error showing the required fields in other dropdown items are not authored.

Could you please suggest whether we can use required fields with show/hide property and let me know your thoughts on this.

 

Thanks

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Rohit_Utreja

@prasanthnapa2904 

It can be achieved by following code
1. add granite:data for all those fields.
2. add extraclientlibs prop at dialog level.

3. create a new clientlib with following code
$(document).on("change", .......capture-the-dropdown...function (e) {

capture all fields by using css class mentioned in granite:data earlier.

capturedField.adaptTo("foundation-field").setRequired(false);

}

 

I hope it helps.

4 replies

TarunKumar
Community Advisor
Community Advisor
March 7, 2023

Hi @prasanthnapa2904 

You can use required field in show/hide for the dropdown but you will have to make sure that required field is removed when you switch back to different selection.
This validation can be applied through jQuery/JavaScript so on show hide of the dropdown selection you will have to add and remove required field.

Kiran_Vedantam
Community Advisor
Community Advisor
March 7, 2023

Hi @prasanthnapa2904 

 

Create a custom JS and add the below logic

 

$("name='./<your field name>'").attr("aria-required", "true");

 

Hope it helps!

Thanks,
Kiran Vedantam.

Rohit_Utreja
Community Advisor
Rohit_UtrejaCommunity AdvisorAccepted solution
Community Advisor
March 7, 2023

@prasanthnapa2904 

It can be achieved by following code
1. add granite:data for all those fields.
2. add extraclientlibs prop at dialog level.

3. create a new clientlib with following code
$(document).on("change", .......capture-the-dropdown...function (e) {

capture all fields by using css class mentioned in granite:data earlier.

capturedField.adaptTo("foundation-field").setRequired(false);

}

 

I hope it helps.

September 21, 2023

@prasanthnapa2904 
Is it working for you? I'm also facing the same problem.

November 6, 2023

Can someone please provide the end to end solution for it.I am also facing the same issue