- Notifications
You must be signed in to change notification settings - Fork18
Submit forms via AJAX with ease
License
github/remote-form
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A function that will enable submitting forms over AJAX.
The function will make a request based on the form usingwindow.fetch
with the payload encoded as URL parameters if the form method is aGET
andFormData
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.
$ npm install --save @github/remote-form
import{remoteForm}from'@github/remote-form'// Make all forms that have the `data-remote` attribute a remote form.remoteForm('form[data-remote]',asyncfunction(form,wants,request){// Before we start the requestform.classList.remove('has-error')form.classList.add('is-loading')letresponsetry{response=awaitwants.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})
<formaction="/signup"method="post"data-remote><labelfor="username">Username</label><inputid="username"type="text"><labelfor="password">Username</label><inputid="password"type="password"><buttontype="submit">Log in</button><divclass="results"></div></form>
Browsers without nativecustom element support require apolyfill.
- Chrome
- Firefox
- Safari
- Microsoft Edge
npm installnpm test
Distributed under the MIT license. See LICENSE for details.
About
Submit forms via AJAX with ease
Topics
Resources
License
Code of conduct
Contributing
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Contributors11
Uh oh!
There was an error while loading.Please reload this page.