mirror of
https://github.com/bigskysoftware/htmx.git
synced 2025-09-28 05:21:18 +00:00
detect multiple attribute and handle getting values
This commit is contained in:
commit
088c6814b8
@ -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) {
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user