Custom Rule - Validaion

Make a text area mandatory based on other field values in ChronoForms.

Overview

The issue occurs when trying to use custom JavaScript to conditionally set a field as required.
Use the field events behavior instead. Set the target field as required and disabled initially, then create rules in the events behavior to enable it when the specified conditions are met.

Answered
ChronoForms v7
Sw SwingeyP 28 Jan, 2021
I am trying to achieve this
If a text field A is <> 0 or text field B <> 0 then
text area is mandatory
else text area is optional.
I can't see a way of conditionally setting a field as required so I have a custom rule in the validation which I think has to be JavaScript?
It's been a log time since I did any JS so please forgive my ignorance.

This doesn't work😟

if if (document.forms['TestNotProcessedAppropriately'].value !=0){
document.getElementById("IncidentDetails").required = true;
}
if if (document.forms['NumberOfIncidentsReported'].value !=0){
document.getElementById("IncidentDetails").required = true;
}

What is the correct syntax for doing this with Chronoforms please?
Max_admin Max_admin 03 Feb, 2021
Answer
you can do this with field events behavior, in your target field, make it required and disabled, then in the events behavior add the following rule:
field A <> 0
field B <> 0
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.