一、流程表单开发过程中,标准的属性联动功能无法满足特定情况下的字段属性联动功能时,使用了以下JavaScript代码进行控制。
二、代码实现了根据表单字段的值动态显示或隐藏特定字段,同时修改字段的属性。这在需要根据用户输入动态调整表单显示
三、代码如下(供参考)
// 将字段名称转换为字段ID
var sfcsfy = WfForm.convertFieldNameToId("sfcsfy");
var hdhylx = WfForm.convertFieldNameToId("hdhylx");
var yjhcprs = WfForm.convertFieldNameToId("yjhcprs", "detail_2");
var yjnbrs = WfForm.convertFieldNameToId("yjnbrs", "detail_2");
var hyzt = WfForm.convertFieldNameToId("hyzt", "detail_2");
var hycd = WfForm.convertFieldNameToId("hycd", "detail_2");
var dyhybh = WfForm.convertFieldNameToId("dyhybh", "detail_3");
// 在文档加载时执行
jQuery(document).ready(function() {
// 绑定字段变更事件
WfForm.bindFieldChangeEvent(sfcsfy, function(obj, id, value) {
toggleFieldVisibility(value);
});
WfForm.bindFieldChangeEvent(hdhylx, function(obj, id, value) {
toggleDyhybhVisibility(value);
});
WfForm.registerAction(WfForm.ACTION_ADDROW + "2", function(index) {
var sfcsfyValue = WfForm.getFieldValue(sfcsfy);
toggleFieldVisibility(sfcsfyValue);
});
// 初始化字段可见性
var initialSfcsfyValue = WfForm.getFieldValue(sfcsfy);
toggleFieldVisibility(initialSfcsfyValue);
var initialHdhylxValue = WfForm.getFieldValue(hdhylx);
toggleDyhybhVisibility(initialHdhylxValue);
});
// 根据值切换字段可见性
function toggleFieldVisibility(value) {
var detailRows = WfForm.getDetailRowCount("detail_2");
var fieldNames = [yjhcprs, yjnbrs, hyzt, hycd];
if (value == "1") {
fieldNames.forEach(function(field) {
changeAttr(field, 2, detailRows);
});
$(".ptoc").hide();
} else {
fieldNames.forEach(function(field) {
changeAttr(field, 3, detailRows);
});
$(".ptoc").show();
}
}
// 根据值切换字段可见性
function toggleDyhybhVisibility(value) {
var detailRows = WfForm.getDetailRowCount("detail_3");
if (value == "0") {
changeAttr(dyhybh, 2, detailRows);
$(".ptoc").show();
} else {
changeAttr(dyhybh, 3, detailRows);
$(".ptoc").hide();
}
}
// 改变字段属性
function changeAttr(id, viewAttr, row) {
if (row != 0) {
for (let i = 0; i < row; i++) {
WfForm.changeFieldAttr(id + "_" + i, viewAttr);
WfForm.changeFieldAttr(id + "_" + i, 4, viewAttr === 3);
}
} else {
WfForm.changeFieldAttr(id, viewAttr);
WfForm.changeFieldAttr(id, 4, viewAttr === 3);
}
}
// 在文档加载时执行
jQuery(document).ready(function() {
WfForm.bindFieldChangeEvent("field9657,field11015,field17547", function(obj, id, value) {
var field9657 = WfForm.getFieldValue("field9657");
var field11015 = WfForm.getFieldValue("field11015");
var field17547 = WfForm.getFieldValue("field17547");
var field17693 = WfForm.getFieldValue("field17693");
if ((field9657 == 0) && field11015 == 0) {
WfForm.changeFieldAttr("field17578", 1);
$('#field17578').closest('tr').hide();
} else if ((field9657 == 0) && field11015 == 1) {
WfForm.changeFieldAttr("field17579", 1);
$('#field17579').closest('tr').hide();
} else if ([1, 2, 3, 4, 5].includes(field9657)) {
WfForm.changeFieldAttr("field17578", 1);
$('#field17578').closest('tr').hide();
WfForm.changeFieldAttr("field17579", 1);
$('#field17579').closest('tr').hide();
} else {
WfForm.changeFieldAttr("field17578", 3);
$('#field17578').closest('tr').show();
WfForm.changeFieldAttr("field17579", 3);
$('#field17579').closest('tr').show();
}
});
function initializeFieldVisibility() {
var field9657 = WfForm.getFieldValue("field9657");
var field11015 = WfForm.getFieldValue("field11015");
var field17547 = WfForm.getFieldValue("field17547");
var field17693 = WfForm.getFieldValue("field17693");
if ((field9657 == 0) && field11015 == 0) {
WfForm.changeFieldAttr("field17578", 1);
$('#field17578').closest('tr').hide();
} else if ((field9657 == 0) && field11015 == 1) {
WfForm.changeFieldAttr("field17579", 1);
$('#field17579').closest('tr').hide();
} else if ([1, 2, 3, 4, 5].includes(field9657)) {
WfForm.changeFieldAttr("field17578", 1);
$('#field17578').closest('tr').hide();
WfForm.changeFieldAttr("field17579", 1);
$('#field17579').closest('tr').hide();
} else {
WfForm.changeFieldAttr("field17578", 3);
$('#field17578').closest('tr').show();
WfForm.changeFieldAttr("field17579", 3);
$('#field17579').closest('tr').show();
}
}
initializeFieldVisibility();
});
标签:changeFieldAttr,field17579,tr,框值,明细表,WfForm,var,field17578,主表
From: https://blog.csdn.net/weixin_55435577/article/details/140455152