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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.