Skip to main content
Participating Frequently
February 5, 2024
Answered

Required codependent fields: checkboxes/dropdowns and textboxes

  • February 5, 2024
  • 1 reply
  • 1288 views

So I have a Dropdown that is required for my form. With 6 options, one of them is a blank option that is the Default one, so User HAS to pick one. Is like this: 

I want this dropDown to only be required if that "blank" option is selected. As of now, it still remains with the red outline whatever you choose. Name of this one is Dropdown1.

Moreover, if the person chooses "Otra" a Texbox called "Forma de Pago Otra" should be set to required. Once you written something, it should stop being required.

 

I want also that if you check a Checkbox called "Check Box3" a textbox called "EmailFacturación" to be set as required, with it turning back to not required once you have written some text into it.

Is any of this possible with the JavaScripts? Appreciate the input, as this is the first form I'm editting and have 0 idea on Javascript lol.

This topic has been closed for replies.
Correct answer try67

Oooh yeah! @try67  This "event.target.required = (event.value==event.target.defaultValue);" works for the calculated to make it not required once text is written. 
However, I need to combine these two codes" event.target.required = this.getField("Dropdown1").valueAsString=="Otra"; (i Didnt change the name of the dropdown, lol)

Meaning, the field for default is not required. Putting that " event.target.required = (event.value==event.target.defaultValue);", makes it ALWAYS required. Only need it to be when "Otra" is chosen. Tried mixing it with ChatGPT but to no avail.


Try this:

 

event.target.required = (event.value==event.target.defaultValue && this.getField("Dropdown1").valueAsString=="Otra");

1 reply

try67
Community Expert
Community Expert
February 5, 2024

The red border indicates that the field is required, not that it's missing a value. To do what you asked for would require using a custom-made script to change the field's border color based on the value, and you would have to turn off the built-in fields highlighting feature for it to work properly. I'm not sure that's a good idea...

 

As for the conditionally required text field, you can use something like this as its custom Calculation script:

 

event.target.required = this.getField("Forma de Pago").valueAsString=="Otra";

 

Same principle applies for the text field that's conditioned by the check-box.

Participating Frequently
February 5, 2024

hey @try67 ty for the reply! Oh 😕😕 yeah... seems more complicated than needed. But, is there way to set the required value to "false" if something has been written on the TextBox? As of now, I write anything, its still required.

 

As for the calculated thing, where do I set that? I tried here in the properties of the textBox i want to be required should "Otra" be chosen. Sorry for Spanish 😞

try67
Community Expert
Community Expert
February 5, 2024

Yes, you can do that. For example, you can use this code as the custom calculation script of the drop-down:

event.target.required = (event.value==event.target.defaultValue);

The same code can also be used for text fields.

 

And the place where you placed the code is correct. Is it not working?