This repository has been archived by the owner on Oct 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.js
51 lines (45 loc) · 1.42 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
var formDataEntries
if (typeof FormData === 'function' && 'entries' in FormData.prototype) {
formDataEntries = function(form) {
return Array.from(new FormData(form).entries())
}
} else {
formDataEntries = function(form) {
var entries = []
var elements = form.elements
for (var i = 0; i < elements.length; i++) {
var el = elements[i]
var tagName = el.tagName.toUpperCase()
if (tagName === 'SELECT' || tagName === 'TEXTAREA' || tagName === 'INPUT') {
var type = el.type,
name = el.name
if (
name &&
!el.disabled &&
type !== 'submit' &&
type !== 'reset' &&
type !== 'button' &&
((type !== 'radio' && type !== 'checkbox') || el.checked)
) {
if (tagName === 'SELECT') {
var options = el.getElementsByTagName('option')
for (var j = 0; j < options.length; j++) {
var option = options[j]
if (option.selected) {
entries.push([name, option.value])
}
}
} else if (type === 'file') {
// eslint-disable-next-line no-console
console.warn('form-data-entries could not serialize <input type=file>', el)
entries.push([name, ''])
} else {
entries.push([name, el.value])
}
}
}
}
return entries
}
}
export default formDataEntries