我们正在尝试为一个字段设置一个复杂的依赖项,我们需要将两者and
和or
条件结合起来。
我该如何实施:
(FieldA and FieldB) or FieldC
正如您所指出的,qbo3Dependency
行为不支持AND
与OR
.
有两种解决方法。
您可以按照以下方式创建 JS 函数:
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');
}
}
然后,添加requireComments()
到 、 和 的处理程序onchange
中。FieldA
FieldB
FieldC
优点:
缺点:
如果您更喜欢远离自定义 JS,您可以使用一些隐藏字段到达您需要去的地方。
创建一个名为 的隐藏字段FielldAFieldB
,并使其依赖于FieldA,FieldB
(AND)。然后,使ExceptionCommentsInput
依赖FieldAFieldB,FieldC
(或)。
优点:
缺点:
FieldAFieldB
)通过电线传递/保存了任务