mirror of
https://github.com/bigskysoftware/htmx.git
synced 2025-09-30 06:21:19 +00:00
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:
commit
d0c255aec8
@ -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
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user