0

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.

enter image description here

How do I implement:

(FieldA and FieldB) or FieldC
Eric Patrick
  • 2,097
  • 2
  • 20
  • 31

1 Answers1

0

As you've noted, the qbo3 Dependency behavior does not support mixing AND with OR

There are two workarounds. 

Custom Javascript

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: 

  • slightly less demanding on the browser
  • no extra data being passed over the wire/saved to the task

Cons:

  • Gotta do custom JS

Hidden Fields

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:

  • easy to configure and maintain

Cons:

  • extra field (FieldAFieldB) passed over the wire/saved the task
Eric Patrick
  • 2,097
  • 2
  • 20
  • 31