Alpaca JS未正确重新排列数组复选框

我有一个Alpaca JS表单,其中包含一系列项目,每个项目都包含一个文本框和一个复选框。出于某种原因,当我使用动态控件更改顺序时,它会成功为文本框重新编号,但不会更改复选框的编号。如果按下了相同的顶部按钮以动态添加新字段,这还会导致分配重复的名称。最终结果是提交表单时传递了不正确的数据。如何解决此问题以正确重新编号复选框?

以下是羊驼毛配置的示例:

$("#form1").alpaca({
    "schema": {
        "title": "Testing checkbox array IDs","description": "Testbox checkbox array test.","type": "object","properties": {
            "form-fields": {
                "title": "Fields","description": "These are the fields.","type": "array","items": {
                    "type": "object","properties": {
                        "field-name": {
                            "type": "string","title": "Field Name","description": "Enter the name for this field.","required": true
                        },"field-box": {
                            "type": "boolean","title": "Field Box","description": "Check this box.","default": false
                        }
                    }
                }
            }
        }
    }
});
fengziyun 回答:Alpaca JS未正确重新排列数组复选框

我找不到纠正行为本身的方法,但是我可以通过向Alpaca定义中添加一个postRender事件来解决该问题,如下所示:

"postRender": function(control) {
    control.childrenByPropertyId["form-fields"].on("move",function() { $('input[type=checkbox]').each(function(index) { $(this).attr("name",$(this).closest("div:has(*[name])").first().attr("name")) }); });
    control.childrenByPropertyId["form-fields"].on("add",$(this).closest("div:has(*[name])").first().attr("name")) }); });
    control.childrenByPropertyId["form-fields"].on("remove",$(this).closest("div:has(*[name])").first().attr("name")) }); });
}

这有点骇人听闻,但它可以工作,因为确实为父对象分配了正确的名称值,并且如果将名称复制到输入元素中,表单将使用这些值进行张贴。

本文链接:https://www.f2er.com/2729065.html

大家都在问