Using FormHandler

In main.js, you need to instantiate a FormHandler instance and pass it the selector for the <form> element: [data-coffee-order="form"]. Create a variable at the top of main.js for this selector so that it can be reused if needed.

(function (window) {
  'use strict';
  var FORM_SELECTOR = '[data-coffee-order="form"]';
  var App = window.App;
...

Next, create a local variable called FormHandler and assign it to App.FormHandler.

(function (window) {
  'use strict';
  var FORM_SELECTOR = '[data-coffee-order="form"]';
  var App = window.App;
  var Truck = App.Truck;
  var DataStore = App.DataStore;
  var FormHandler = App.FormHandler;
  var myTruck = new Truck('ncc-1701', new DataStore());
  ...

At the end of the main.js module, call ...

Get Front-End Web Development: The Big Nerd Ranch Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.