AEM Forms Forum
Q: Make a text field mandatory if checkbox is selected
How can I make a group of text fields mandatory when a certain checkbox is checked?
tony.conti@chenegaess.com, May 26th, 2022 15:05:53
jp@smartdoctech.comcommented:May 27th, 2022
Hi Tony,
You can put this JavaScript in the change event of the checkbox. I am assuming that the checkbox has an On Value of 1 and an Off Value of 0.
if (this.rawValue == "1")
{
//TextField1.access = "readOnly";
TextField1.validate.nullTest = "error";
// TextField1.validate.nullTest = "warning";
}
else
{
TextField1.validate.nullTest = "disabled";
}
You can set the validation to either error or warning depending on what you want. I also attached a sample XDP file for you.
You can put this JavaScript in the change event of the checkbox. I am assuming that the checkbox has an On Value of 1 and an Off Value of 0.
if (this.rawValue == "1")
{
//TextField1.access = "readOnly";
TextField1.validate.nullTest = "error";
// TextField1.validate.nullTest = "warning";
}
else
{
TextField1.validate.nullTest = "disabled";
}
You can set the validation to either error or warning depending on what you want. I also attached a sample XDP file for you.
jp@smartdoctech.comcommented:May 27th, 2022
checkbox-sets-TextField-to-mandatory.xdp
tony.conti@chenegaess.comcommented:May 27th, 2022
Thank you this is awesome.
-Tony
-Tony
