Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
respect the `enctype` attribute on form elements when submitting requests
  • Loading branch information
strangeRabbit777 committed May 13, 2022
1 parent 7ea7b2f commit bc49ae9
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/htmx.js
Original file line number Diff line number Diff line change
Expand Up @@ -2291,6 +2291,11 @@ return (function () {
return swapSpec;
}

function usesFormData(elt) {
return getClosestAttributeValue(elt, "hx-encoding") === "multipart/form-data" ||
(matches(elt, "form") && getRawAttribute(elt, 'enctype') === "multipart/form-data");
}

function encodeParamsForBody(xhr, elt, filteredParameters) {
var encodedParameters = null;
withExtensions(elt, function (extension) {
Expand All @@ -2301,8 +2306,7 @@ return (function () {
if (encodedParameters != null) {
return encodedParameters;
} else {
if (getClosestAttributeValue(elt, "hx-encoding") === "multipart/form-data" ||
(matches(elt, "form") && getRawAttribute(elt, 'enctype') === "multipart/form-data")) {
if (usesFormData(elt)) {
return makeFormData(filteredParameters);
} else {
return urlEncode(filteredParameters);
Expand Down Expand Up @@ -2639,7 +2643,7 @@ return (function () {
var allParameters = mergeObjects(rawParameters, expressionVars);
var filteredParameters = filterValues(allParameters, elt);

if (verb !== 'get' && getClosestAttributeValue(elt, "hx-encoding") == null) {
if (verb !== 'get' && !usesFormData(elt)) {
headers['Content-Type'] = 'application/x-www-form-urlencoded';
}

Expand All @@ -2648,6 +2652,7 @@ return (function () {
path = getDocument().location.href;
}


var requestAttrValues = getValuesForElement(elt, 'hx-request');

var requestConfig = {
Expand Down

0 comments on commit bc49ae9

Please sign in to comment.