From 7576e21ab19f2bcdc24a6d9fa8911c6651ddb1c3 Mon Sep 17 00:00:00 2001 From: Ben Weller Date: Wed, 25 Nov 2020 15:40:57 -0600 Subject: [PATCH] handle multi-select when "multiple" attr is present w/o value --- src/htmx.js | 2 +- test/core/ajax.js | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/htmx.js b/src/htmx.js index ecccbfeb..06903a2e 100644 --- a/src/htmx.js +++ b/src/htmx.js @@ -1489,7 +1489,7 @@ return (function () { if (shouldInclude(elt)) { var name = getRawAttribute(elt,"name"); var value = elt.value; - if (!!getRawAttribute(elt, 'multiple')) { + if (hasAttribute(elt, 'multiple')) { value = toArray(elt.querySelectorAll("option:checked")).map(function (e) { return e.value }); } // include file inputs diff --git a/test/core/ajax.js b/test/core/ajax.js index 2af5731d..176912c0 100644 --- a/test/core/ajax.js +++ b/test/core/ajax.js @@ -397,6 +397,40 @@ describe("Core htmx AJAX Tests", function(){ values.should.deep.equal({multiSelect:["m1", "m3"]}); }); + it('properly handles multiple select input when "multiple" attribute is empty string', function() + { + var values; + this.server.respondWith("Post", "/test", function (xhr) { + values = getParameters(xhr); + xhr.respond(204, {}, ""); + }); + + var form = make('
' + + '' + + '
'); + + form.click(); + this.server.respond(); + values.should.deep.equal({}); + + byId("m1").selected = true; + form.click(); + this.server.respond(); + values.should.deep.equal({multiSelect:"m1"}); + + byId("m1").selected = true; + byId("m3").selected = true; + form.click(); + this.server.respond(); + values.should.deep.equal({multiSelect:["m1", "m3"]}); + }); + + it('properly handles two multiple select inputs w/ same name', function() { var values;