detect multiple attribute and handle getting values

This commit is contained in:
carson 2020-09-01 19:10:50 -06:00
commit 088c6814b8
2 changed files with 35 additions and 0 deletions

View File

@ -1235,6 +1235,9 @@ return (function () {
if (shouldInclude(elt)) {
var name = getRawAttribute(elt,"name");
var value = elt.value;
if (!!getRawAttribute(elt, 'multiple')) {
value = toArray(elt.querySelectorAll("option:checked")).map(function (e) { return e.value });
}
if (name != null && value != null) {
var current = values[name];
if(current) {

View File

@ -334,6 +334,38 @@ describe("Core htmx AJAX Tests", function(){
}, 20);
});
it('properly handles multiple select input', 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 id="multiSelect" name="multiSelect" multiple="multiple">'+
'<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>'+
'</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 checkbox inputs', function()
{
var values;