fix(form): 修复 select 未选中时 form.val 获取到的值为 null 的问题 (#2475)

pull/2503/head
morning-star 2025-02-14 16:38:01 +08:00 committed by GitHub
parent 317512bbb1
commit b38d7fd443
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 1 deletions

View File

@ -158,7 +158,12 @@ layui.define(['lay', 'layer', 'util'], function(exports){
}
if(/^(checkbox|radio)$/.test(item.type) && !item.checked) return; // 复选框和单选框未选中,不记录字段
field[init_name || item.name] = othis.val();
// select 多选用 jQuery 方式取值,未选中 option 时,
// jQuery v2.2.4 及以下版本返回 null以上(3.x) 返回 []。
// 统一规范化为 [],参考 https://github.com/jquery/jquery/issues/2562
field[init_name || item.name] = (this.tagName === 'SELECT' && typeof this.getAttribute('multiple') === 'string')
? othis.val() || []
: this.value;
});
return field;