Skip to content
This repository has been archived by the owner on Jan 1, 2023. It is now read-only.

Commit

Permalink
Merge pull request #3 from rodrigoreeis/feature/form2/file-upload
Browse files Browse the repository at this point in the history
Feature/form2/file upload
  • Loading branch information
Javiani authored May 26, 2021
2 parents 3b05c2e + a3d88f9 commit 235ad1e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion form2/dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 14 additions & 4 deletions form2/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,22 @@ export const getFormData = (form) => {
if (el.name) {
const therules = (new Function(`return ${el.dataset.rules}`))()
const rules = therules ? therules : null

const isCheckbox = (el.type && (el.type == 'checkbox'))
const value = isCheckbox
? el.checked ? el.value : ''
: el.form[el.name].value
acc[el.name] = value
const isFile = (el.type && (el.type == 'file'))

acc[el.name] = el.form[el.name].value

if (isCheckbox) {
acc[el.name] = el.checked ? el.value : ''
}

if (isFile && el.value) {
acc[el.name] = el.files
}

}

return acc
}, {})

Expand Down
Loading

0 comments on commit 235ad1e

Please sign in to comment.