fix: 修复表单提交参数重复问题 (#22)#23
Open
PrintNow wants to merge 2 commits into
Open
Conversation
- Builder::render() 中 renderHiddenFields() 被调用两次,导致 _method、 _previous_ 等隐藏字段在 DOM 中重复,ajaxSubmit 序列化时参数翻倍 - MultipleSelect 的隐藏 input 在有选中值时仍提交空值,改为按需禁用
Owner
Author
修复审查Fix 1 —
|
| 路径 | container.blade.php | build() | 结果 |
|---|---|---|---|
| hasColumns | ✓ doWrap 内 | 不调用 | 1次 ✓ |
| 默认(无columns无blocks) | ✓ prepend 进 column | 无参数 | 1次 ✓ |
| hasBlocks | ✓ block column 内 | 无参数 | 1次 ✓ |
renderHiddenFields() 仅在 container.blade.php:18 和 Builder.php(方法定义)两处出现,无其他调用方。无副作用。
Fix 2 — MultipleSelect 隐藏 input 按需禁用
| 场景 | 行为 | 正确 |
|---|---|---|
| 页面加载,有预选值 | PHP 输出 disabled,hidden input 不提交 | ✓ |
| 页面加载,无预选值 | 提交空值 → Helper::array 过滤为 [] |
✓ |
| 用户选中值 | change.select2 → JS 禁用 hidden input |
✓ |
| 用户清空选择 | change.select2 → JS 启用 hidden input |
✓ |
| 多个实例 | $selector 含字段名,唯一不冲突 |
✓ |
| Select2 未初始化 | 原生 select 可用,PHP disabled 处理初始状态 | ✓ |
.next() 查找 |
Select2 保留原生 select,.next() 能找到 hidden input |
✓ |
$(this).val() 为 null |
?.length 可选链安全处理 |
✓ |
未发现遗漏的边界情况,两个修复均安全。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Builder::render()中renderHiddenFields()被调用两次,导致_method、_previous_等隐藏字段在 DOM 中重复问题根因
隐藏字段重复
Builder::render()在默认布局路径(无 columns、无 blocks)和 hasBlocks 路径中,renderHiddenFields()被调用了两次:container.blade.php:18—{!! $form->renderHiddenFields() !!}Builder::render():726—$this->layout->build($this->renderHiddenFields())jquery-form 的
ajaxSubmit通过form.elements序列化所有表单元素,两个重复的<input>都被收集,导致 payload 中出现_method=PUT&_method=PUT。MultipleSelect 空值重复
multipleselect.blade.php中<input type="hidden" name="{{$name}}[]" />与<select>同名,选中值时两者同时提交,导致数组混入空值。修复方式
Builder::render()中build()对renderHiddenFields()的冗余调用disabled,Select2 变更时通过change.select2事件切换Test plan
_method和_previous_不再重复Closes #22