Merge pull request #243 from e9labs/feature/handle-multiple-attr-no-value

handle multi-select when "multiple" attr is present w/o value
This commit is contained in:
1cg 2020-11-29 09:51:49 -07:00 committed by GitHub
commit d0c255aec8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 1 deletions

View File

@ -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

View File

@ -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 hx-post="/test" hx-trigger="click">' +
'<select name="multiSelect" id="id_question_list" multiple="" tabindex="-1" aria-hidden="true">' +
'<option id="m1" value="m1">m1</option>'+
'<option id="m2" value="m2">m2</option>'+
'<option id="m3" value="m3">m3</option>'+
'<option id="m4" value="m4">m4</option>'+
'</select>' +
'</form>');
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;