Skip to content

fromFormElement #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Breaking changes:

New features:
- Added roles declarations to forbid unsafe coercions (#7)
- Can create a new `FormData` from `HTMLFormElement` (#15)

Bugfixes:
- Access the "timeout" property instead of "statusText" in `timeout` (#12)
Expand Down
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"purescript-datetime": "master",
"purescript-http-methods": "main",
"purescript-web-dom": "master",
"purescript-web-file": "master"
"purescript-web-file": "master",
"purescript-web-html": "master"
}
}
4 changes: 4 additions & 0 deletions src/Web/XHR/FormData.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ exports["new"] = function () {
return new FormData();
};

exports._fromFormElement = function(form) {
return new FormData(form);
};

exports._append = function (name, value, fd) {
fd.append(name, value);
};
Expand Down
6 changes: 6 additions & 0 deletions src/Web/XHR/FormData.purs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Data.Nullable (Nullable, toNullable)
import Effect (Effect)
import Effect.Uncurried as Fn
import Web.File.Blob (Blob)
import Web.HTML.HTMLFormElement (HTMLFormElement)

foreign import data FormData :: Type

Expand All @@ -36,6 +37,9 @@ derive instance newtypeFileName :: Newtype FileName _

foreign import new :: Effect FormData

fromFormElement :: HTMLFormElement -> Effect FormData
fromFormElement formElement = Fn.runEffectFn1 _fromFormElement formElement

append :: EntryName -> String -> FormData -> Effect Unit
append name value fd = Fn.runEffectFn3 _append name value fd

Expand All @@ -54,6 +58,8 @@ set name value fd = Fn.runEffectFn3 _set name value fd
setBlob :: EntryName -> Blob -> Maybe FileName -> FormData -> Effect Unit
setBlob name value filename fd = Fn.runEffectFn4 _setBlob name value (toNullable filename) fd

foreign import _fromFormElement :: Fn.EffectFn1 HTMLFormElement FormData

-- void append(USVString name, USVString value);
foreign import _append :: Fn.EffectFn3 EntryName String FormData Unit

Expand Down