Skip to content
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
18 changes: 18 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"env": {
"esm": {
"presets": ["github"]
},
"umd": {
"plugins": [
["@babel/plugin-transform-modules-umd", {
"globals": {
"selector-set": "SelectorSet"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The UMD build was looking for selectorSet in global but in the selector-set UMD build the global is set to SelectorSet:

https://github.com/josh/selector-set/blob/master/selector-set.js#L7

}
}]
],
"moduleId": "remoteForm",
"presets": ["github"]
}
}
}
24 changes: 24 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"extends": [
"plugin:github/es6",
"plugin:github/browser",
"plugin:github/flow"
],
"overrides": [
{
"files": "test/**/*.js",
"rules": {
"flowtype/require-valid-file-annotation": "off",
"github/unescaped-html-literal": "off",
"eslint-comments/no-use": "off"
},
"env": {
"mocha": true
},
"globals": {
"assert": true,
"remoteForm": true
}
}
]
}
11 changes: 11 additions & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[ignore]

[include]

[libs]

[lints]

[options]

[strict]
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist/
node_modules/
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2019 GitHub, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
74 changes: 74 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,75 @@
# remote-form

A function that will enable submitting forms over AJAX.

The function will make a request based on the form using `window.fetch` with the payload encoded as URL parameters if the form method is a `GET` and `FormData` for all the other methods.

The request object is available in the callback function, allowing the headers and body to be modified before the request is sent.

## Installation

```
$ npm install --save @github/remote-form
```

## Usage

```js
import {remoteForm} from '@github/remote-form'

// Make all forms that have the `data-remote` attribute a remote form.
remoteForm('form[data-remote]', async function(form, wants, request) {
// Before we start the request
form.classList.remove('has-error')
form.classList.add('is-loading')

let response
try {
response = await wants.html()
} catch (error) {
// If the request errored, we'll set the error state and return.
form.classList.remove('is-loading')
form.classList.add('has-error')
return
}

// If the request succeeded we can do something with the results.
form.classList.remove('is-loading')
form.querySelector('.results').innerHTML = response.html
})
```

```html
<form action="/signup" method="post" data-remote>
<label for="username">Username</label>
<input id="username" type="text" />

<label for="password">Username</label>
<input id="password" type="password" />

<button>Log in</button>
</form>
```

## Browser support

Browsers without native [custom element support][support] require a [polyfill][].

- Chrome
- Firefox
- Safari
- Microsoft Edge

[support]: https://caniuse.com/#feat=custom-elementsv1
[polyfill]: https://github.com/webcomponents/custom-elements

## Development

```
npm install
npm test
```

## License

Distributed under the MIT license. See LICENSE for details.
Loading