Skip to content

Commit

Permalink
Improve getInputValues
Browse files Browse the repository at this point in the history
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:
10e068f
  • Loading branch information
bencroker authored Jan 22, 2021
1 parent 10e068f commit a10e43d
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/htmx.js
Original file line number Diff line number Diff line change
Expand Up @@ -1597,8 +1597,7 @@ return (function () {
var processed = [];
var values = {
form: {},
element: {},
includes: {},
other: {},
};
var errors = [];

Expand All @@ -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};
}
Expand Down

0 comments on commit a10e43d

Please sign in to comment.