mirror of
https://github.com/bigskysoftware/htmx.git
synced 2025-09-29 22:11:22 +00:00
Fix handling of repeated empty inputs (#1144)
Native form handling submits repeated empty inputs as an array with an empty value for each input, but htmx would only submit the first non-empty input and any following inputs. Fix the value collection code so that it correctly distinguishes between empty values and new inputs.
This commit is contained in:
parent
90db47fbea
commit
8520f6f374
@ -2142,7 +2142,7 @@ return (function () {
|
||||
// and the new value could be arrays, so we have to handle all four cases :/
|
||||
if (name != null && value != null) {
|
||||
var current = values[name];
|
||||
if(current) {
|
||||
if (current !== undefined) {
|
||||
if (Array.isArray(current)) {
|
||||
if (Array.isArray(value)) {
|
||||
values[name] = current.concat(value);
|
||||
|
@ -78,6 +78,12 @@ describe("Core htmx Parameter Handling", function() {
|
||||
vals['do'].should.deep.equal(['rey1', 'rey2']);
|
||||
})
|
||||
|
||||
it('Double empty values are included as array in correct order', function () {
|
||||
var form = make('<form><input id="i1" name="do" value=""/><input id="i2" name="do" value="rey"/><input id="i3" name="do" value=""/></form>');
|
||||
var vals = htmx._('getInputValues')(byId("i3")).values;
|
||||
vals['do'].should.deep.equal(['', 'rey', '']);
|
||||
})
|
||||
|
||||
it('hx-include works with form', function () {
|
||||
var form = make('<form id="f1"><input id="i1" name="foo" value="bar"/><input id="i2" name="do" value="rey"/><input id="i2" name="do" value="rey"/></form>');
|
||||
var div = make('<div hx-include="#f1"></div>');
|
||||
|
Loading…
x
Reference in New Issue
Block a user