Skip to content

Instantly share code, notes, and snippets.

@ruan4261
Last active June 30, 2021 09:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruan4261/a43366f39344906f1125fa47f601fe45 to your computer and use it in GitHub Desktop.
Save ruan4261/a43366f39344906f1125fa47f601fe45 to your computer and use it in GitHub Desktop.
/**
* 对指定明细表指定字段(列)绑定变化事件, 绑定的数据行包括已存在的数据行及未来新建的数据行(该方法只需执行一次)
*
* @param detailIndex 明细表索引是对于当前流程而言的, 与模板无关(同一个明细表在不同节点模板内拥有相同的索引)
* @param fieldId 单个字段的id
* @param func 可用参数列表[rowIdx, changedElement]
*/
function bindDetailFieldChangeEvent(detailIndex, fieldId, func) {
var bindEvent = function (idx) {
var jq = jQuery("#field" + fieldId + "_" + idx);
var ele = jq[0];
jq.bindPropertyChange(func.bind(undefined, idx, ele));
};
// bind data row already existed
var idxSeq = getCheckNodeIndexSeq(detailIndex);
for (var i = 0; i < idxSeq.length; i++) {
var idx = idxSeq[i];
bindEvent(idx);
}
// bind new data row
window["_customAddFun" + detailIndex] = function () {
var seq = getCheckNodeIndexSeq();
var len = seq.length;
var lastIdx = seq[len - 1];
bindEvent(lastIdx);
};
}
(function () {
if (!Array.isArray(window._check_customize_))
window._check_customize_ = []
window._check_customize_.push(function () {
// enter your custom verification program
})
window.checkCustomize = function () {
var len = window._check_customize_.length
for (var i = 0; i < len; i++) {
var checkCustomize = window._check_customize_[i]
if (typeof checkCustomize === 'function') {
try {
if (checkCustomize() === false)
return false
} catch (e) {
alert('[checkCustomize]校验程序异常!')
if (window.console) {
console.log(window._check_customize_[i])
console.log(e)
} else alert(e.toString())
return false
}
}
}
return true
}
// ie8+
try {
Object.defineProperty(window, 'checkCustomize', {writable: false})
Object.defineProperty(window, '_check_customize_', {writable: false})
} catch (e) {
}
})()
/**
* 获取表单页面中指定明细表所有行数据的索引
*
* @param detailIndex 明细表索引是对于当前流程而言的, 与模板无关(同一个明细表在不同节点模板内拥有相同的索引)
*/
function getCheckNodeIndexSeq(detailIndex) {
var key = "check_node_" + detailIndex;
var jqSeq = jQuery('[name="' + key + '"]');
var idxSeq = [];
for (var i = 0; i < jqSeq.length; i++) {
idxSeq[i] = jqSeq[i].value;
}
return idxSeq;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment