Using Deferreds with Callback-Only APIs
Sometimes you will need to coordinate your
code with callback-only APIs, such as event listeners.
Currently, formHandler.addSubmitHandler resets the form and
focuses on the first element – no matter what happens with the
Ajax request. However, you only want those things to happen if the Ajax
request is successful. Put another way, you only want those things to
happen if the
Deferred is fulfilled.
How can you know whether the
Deferred is fulfilled? Your function
argument to addSubmitHandler can return the
Deferred, and inside of addSubmitHandler you can
chain a .then call to the
In main.js, add a
keyword to the callback.
... formHandler.addSubmitHandler(function ...