Skip to content

Commit

Permalink
serialize files attribute of file input element
Browse files Browse the repository at this point in the history
  • Loading branch information
rmorshea committed May 20, 2021
1 parent d55a28f commit f0d00b7
Showing 1 changed file with 9 additions and 2 deletions.
Expand Up @@ -7,7 +7,9 @@ function serializeEvent(event) {

const target = event.target;
if (target.tagName in targetTransforms) {
Object.assign(data, targetTransforms[target.tagName](target));
targetTransforms[target.tagName].forEach((trans) =>
Object.assign(data, trans(target))
);
}

return data;
Expand All @@ -20,18 +22,23 @@ const targetTransformCategories = {
hasCurrentTime: (target) => ({
currentTime: target.currentTime,
}),
hasFiles: (target) => {
return target.type == "file" ? { files: target.files } : {};
},
};

const targetTagCategories = {
hasValue: ["BUTTON", "INPUT", "OPTION", "LI", "METER", "PROGRESS", "PARAM"],
hasCurrentTime: ["AUDIO", "VIDEO"],
hasFiles: ["INPUT"],
};

const targetTransforms = {};

Object.keys(targetTagCategories).forEach((category) => {
targetTagCategories[category].forEach((type) => {
targetTransforms[type] = targetTransformCategories[category];
const transforms = targetTransforms[type] || (targetTransforms[type] = []);
transforms.push(targetTransformCategories[category]);
});
});

Expand Down

0 comments on commit f0d00b7

Please sign in to comment.