From a10e43d619dc340aa324d37772c06a69a2f47ec9 Mon Sep 17 00:00:00 2001 From: Ben Croker <57572400+bencroker@users.noreply.github.com> Date: Fri, 22 Jan 2021 09:47:58 +0100 Subject: [PATCH] Improve `getInputValues` This improves the `getInputValues` method by non overriding included element values with the main element's value. This should make the `Two inputs are included twice when they have the same name` test pass: https://github.com/bigskysoftware/htmx/commit/10e068fcaa4bdcf3190a9eb818064dc08ba8f7a4 --- src/htmx.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/htmx.js b/src/htmx.js index 55a64ab98..e0032c9b2 100644 --- a/src/htmx.js +++ b/src/htmx.js @@ -1597,8 +1597,7 @@ return (function () { var processed = []; var values = { form: {}, - element: {}, - includes: {}, + other: {}, }; var errors = []; @@ -1611,19 +1610,19 @@ return (function () { } // include the element itself - processInputValue(processed, values.element, errors, elt, validate); + processInputValue(processed, values.other, errors, elt, validate); // include any explicit includes var includes = getClosestAttributeValue(elt, "hx-include"); if (includes) { var nodes = getDocument().querySelectorAll(includes); forEach(nodes, function(node) { - processInputValue(processed, values.includes, errors, node, validate); + processInputValue(processed, values.other, errors, node, validate); }); } - var mergedValues = mergeObjects(values.includes, values.element); - mergedValues = mergeObjects(mergedValues, values.form); + // values in closest form take precedence + var mergedValues = mergeObjects(values.other, values.form); return {errors:errors, values:mergedValues}; }