We are trying to set up a complicated dependency for a field, where we need to do a combination of both and
and or
condition.
How do I implement:
(FieldA and FieldB) or FieldC
We are trying to set up a complicated dependency for a field, where we need to do a combination of both and
and or
condition.
How do I implement:
(FieldA and FieldB) or FieldC
As you've noted, the qbo3 Dependency
behavior does not support mixing AND
with OR
.
There are two workarounds.
You can create a JS function along these lines:
function requireComments() {
var fieldA = document.id('FieldA').value;
var fieldB = document.id('FieldB').value;
var fieldC = document.id('FieldC').value;
var commentField = document.id('ExceptionCommentsInput');
var required = (fieldA && fieldB) || fieldC; // same as (fieldA.value != '' && fieldB.value !='') || fieldC.value != '';
if (required) {
commentField.removeAttribute('disabled');
commentField.addClass('required');
commentField.removeClass('disabled');
} else {
commentField.setAttribute('disabled');
commentField.removeClass('required');
commentField.addClass('disabled');
}
}
Then, add requireComments()
to the onchange
handlers of FieldA
, FieldB
, and FieldC
.
Pros:
Cons:
If you prefer to stay away from the custom JS, you can get where you need to go with some hidden fields.
Create a hidden field called FielldAFieldB
, and make it dependent on FieldA,FieldB
(AND).
Then, make ExceptionCommentsInput
dependent on FieldAFieldB,FieldC
(OR).
Pros:
Cons:
FieldAFieldB
) passed over the wire/saved the task