Add the option to use FormData to encode the form elements (#153)

* Add the option to use FormData to encode the form elements

If the form's enctype attribute is set to "multipart/form-data",
use FormData to encode the form's elements.
This commit was merged in pull request #153.
This commit is contained in:
BehindTheMath
2018-04-29 15:05:22 -04:00
committed by GitHub
parent 7d26a75fdf
commit e49d8947f7
4 changed files with 54 additions and 7 deletions

View File

@@ -152,3 +152,33 @@ tape("test form elements parsed correctly", function(t) {
t.end()
})
tape("test form.enctype=\"multipart/form-data\"", function(t) {
t.plan(4)
var form = document.createElement("form")
form.enctype = "multipart/form-data"
var input = document.createElement("input")
input.name = "input"
input.value = "value"
form.appendChild(input)
var pjax = {
options: {},
loadUrl: function(href, options) {
t.equals(options.requestOptions.requestParams, undefined, "form elements not parsed manually")
t.true(options.requestOptions.formData instanceof FormData, "requestOptions.formData is a FormData")
t.equals(Array.from(options.requestOptions.formData.entries()).length, 1, "correct number of FormData elements")
t.equals(options.requestOptions.formData.get("input"), "value", "FormData element value set correctly")
}
}
attachForm.call(pjax, form)
form.action = window.location.protocol + "//" + window.location.host + "/internal"
trigger(form, "submit")
// see loadUrl defined above
t.end()
})