Revert "feat(form): 相同 name 的 checkbox,将值序列化为数组 (#2428)" (#2443)

This reverts commit c7452c788a.
This commit is contained in:
morning-star 2024-12-30 14:04:46 +08:00 committed by GitHub
parent 0d17679d01
commit 83503e5e8a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -113,7 +113,7 @@ layui.define(['lay', 'layer', 'util'], function(exports){
type = itemElem[0].type;
// 如果为复选框
if(itemElem.length === 1 && type === 'checkbox'){
if(type === 'checkbox'){
itemElem[0].checked = value;
} else if(type === 'radio') { // 如果为单选框
itemElem.each(function(){
@ -154,12 +154,7 @@ layui.define(['lay', 'layer', 'util'], function(exports){
}
if(/^(checkbox|radio)$/.test(item.type) && !item.checked) return; // 复选框和单选框未选中,不记录字段
var n = init_name || item.name;
var v = othis.val();
// 相同 name 的字段,将值合并到数组
field[n] = field[n] === undefined ? v
: $.isArray(field[n]) ? field[n].concat(v)
: [field[n], v];
field[init_name || item.name] = othis.val();
});
return field;