Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Conditional required fields not working

Avatar

Level 2

Hello

I have a problem with conditionally required fields. It works only partially. I will explain the situation:

I have a dropdown field with values from 0 to 9 and there are other fields: date fields and several text fields. The other fields become required if the selected values from the dropdown are either 2 or 6.

The problem is when I go from the value 6 or 2 to some other value then 2 and 6 in the dropdown. In other words, the other fields don't become optional after they were required. I was using the change event for the dropdown with java script as script language.

Here is a more simpler example with a option field which I also tried:

adobe1.PNG

after that I click option 1:

adobe2.PNG

and it's still required, although it shouldn't be. This time I was using the click event.

I used the script from this thread: Conditional Required Fields

I hope someone can help me.

Thanks and best regards

10 Replies

Avatar

Level 3

Hi Lvica,

This question has already been answered on community. Here is the answer below.

11.PNG

Get your radio button binding values from here.

binding.PNG 22.PNG

33.PNG

Avatar

Level 2

It works with option fields but what if the option field is a dropdown?

On the drop down it works only in validation but not perfectly.

I have a dropdown with values from 0 to 9. Values 0 and 1 are making the other fields optional and changing it to other values makes the other fields required or mandatory. It works if I go from 6 to 1 directly on the dropdown but if I go from 6 to 5 and then to 1, the other fields are still required. I need to switch directly from the value that makes the fields required to the value that makes the other fields optional.

Avatar

Level 3

With dropdown it is working fine. Place it in exit event.

dd.PNG

Avatar

Level 2

Hello

Sorry for reviving this thread but I need some help.

I know how to make conditional required field if one field has some specific value but how to make the same with 2 fields. Example:

if (field1.rawValue == 1 && field2 == 2) {

date1.mandatory = "error";

dropdown.mandatory = "error";

}

else {

date1.mandatory = "disabled";

dropdown.mandatory = "disabled";

}

I tried it with this formula but it's not working. The fields are still optional.

Avatar

Level 2

I need this urgently. Its very important.

Avatar

Level 3

Hi Ivica,

There is a small error.

Try

if (field1.rawValue == 1 && field2.rawValue == 2) {


Regards

Arvind

Avatar

Level 2

This was some small example that I wrote when I made the post. On LiveCylce I tried it with different but similar formulas. I even used selectedIndex or boundItem instead of rawValue but it didn't work.

Avatar

Level 3

if (dd1.rawValue == "1" && dd2.rawValue == "1") {

NumericField1.mandatory = "error";

}

else {

NumericField1.mandatory = "disabled"; }

Put this code in both dropdown exit event, dropdown values are taken as text not numbers so always put "". Its working great here.

See sample below.

Dropbox - mandaotry II.pdf

Hope this would help

Avatar

Level 2

Thanks for the example. It helped me a lot.

I found a way. The problem was that one of the conditional fields was an option field. From the option field I made a dropdown and now it seems to be working. I will make a better test on monday to see if its working like it should.

Thanks again for the help.