node package manager


Wrap your regular form with moar ajax.

Compose Remote Form

Wraps good old forms and transforms them into AJAX forms.

npm install compose-remote-form
var RemoteForm = require('compose-remote-form')

More details about each fired "event" below.

// Register single callbacks: 
RemoteForm.on('#formid', 'error', function(body, status, xhr) {
  console.log('success!', body)
// Register multiple callbacks: 
var formEl = document.querySelector('#formid')
RemoteForm.on(formEl, {
  beforeSend: function(req){
    console.log('submitting the form...')
  success: function(body, status, xhr){
    console.log('success!', body)
  error: function(xhr, status, error){
    console.log('error :(', error)
  complete: function(xhr, status){
    console.log('complete:', status)

Without the need to bind any extra events, you can specify beforeSend, success and error functions in your extension of RemoteForm (shown in the example code above.)

Fired before sending the AJAX request. There's no stopping it, but it's useful to notify the user that something is happening, disable buttons/inputs, etc.

It's fired with the superagent request (req) object.

Upon success, this is fired with the returned body, response status and the ajax request xhr object.

When an error occurs, this event is fired with the original ajax request xhr object and the error that the ajax library suffered.

It'll fire in the event of a request not getting through (due to CORS, server down, etc.), a server error (5xx) or a client error (4xx).

The complete event is fired at the end of the ajax submission lifecycle, regardless of success or failure. You might use this event to perform some cleanup action no matter the end result of a form submission.