Created
August 13, 2013 22:56
-
-
Save rapzo/6226518 to your computer and use it in GitHub Desktop.
From http://reefpoints.dockyard.com/javascript/2012/04/16/using-backbone-views-with-rails-jquery-ujs.html
Using Backbone & UJS, for whatever reason :-)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var FormView = Backbone.View.extend({ | |
el: '#form', | |
events: { | |
// Fired automatically when a file-type input is detected with a | |
// non-blank value. You can use this hook to implement a handler that | |
// will deal with those non-blank file inputs. Returning false will | |
// disallow standard form submission. | |
'ajax:aborted:file' : 'ajaxAbortedFile', | |
// Fired when there are required inputs which have been left blank. | |
// You can use this handler to deal with those blank required inputs. | |
// Returning false will submit the form anyway. | |
'ajax:aborted:required' : 'ajaxAbortedRequired', | |
// First event fired for any remote enabled form. Stopping this event | |
// will cancel the ajax request | |
'ajax:before' : 'ajaxBefore', | |
// Fired before the ajax request is sent. Stopping this event will | |
// cancel the ajax request. Commonly used to customize certain request | |
// headers | |
'ajax:beforeSend' : 'ajaxBeforeSend', | |
// Fired after completion, if the HTTP response was a success | |
'ajax:success' : 'ajaxSuccess', | |
// Fired after completion, if the server returned an error | |
'ajax:error' : 'ajaxError', | |
// Fired after the request has been completed, no matter what outcome | |
'ajax:complete' : 'ajaxComplete' | |
}, | |
ajaxAbortedFile: function(e, elements){ | |
}, | |
ajaxAbortedRequired: function(e, elements){ | |
}, | |
ajaxBefore: function(e){ | |
}, | |
ajaxBeforeSend: function(e, xhr, settings){ | |
}, | |
ajaxSuccess: function(e, data, status, xhr){ | |
}, | |
ajaxError: function(e, xhr, status, error){ | |
}, | |
ajaxComplete: function(e, xhr, status){ | |
} | |
}); | |
$(function(){ | |
window.view = new FormView(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment