Could not find element with selector: [data-coffee-order="checkList"]


#1

Blockquotechecklist.js:15 Uncaught Error: Could not find element with selector: [data-coffee-order=“checkList”]
at new CheckList (checklist.js:15)
at main.js:12
at main.js:20

Blockquote (function(window){
‘use strict’;
var FORM_SELECTOR = ‘[data-coffee-order=“form”]’;
var CHECKLIST_SELECTOR = ‘[data-coffee-order=“checkList”]’;
var App = window.App;
var Truck = App.Truck;
var DataStore = App.DataStore;
var FormHandler = App.FormHandler;
var CheckList = App.CheckList;
var myTruck = new Truck(‘Serenity’, new DataStore());
window.myTruck = myTruck;
var checkList = new CheckList(CHECKLIST_SELECTOR);
var formHandler = new FormHandler(FORM_SELECTOR);
formHandler.addSubmitHandler(function(data){
myTruck.createOrder(data);
checkList.addRow(data);
});
})(window);

(function (window) {
‘use strict’;

var App = window.App || {};
var $ = window.jQuery;

function CheckList(selector){
if(!selector){
throw new Error(‘No selector provided’);
}

this.$element = $(selector);
if(this.$element.length === 0){
  throw new Error('Could not find element with selector: ' + selector);
}

}

CheckList.prototype.addRow = function (coffeeOrder){
var rowElement = new Row(coffeeOrder);
this.$element.append(rowElement.$element);
};

function Row(coffeeOrder){
//Constructor code will go here
var div = (’

’, {
‘data-coffee-order’: ‘checkbox’,
‘class’: ‘checkbox’
});
var label = (’’);
var $checkbox = $('<input></input>',{
  type: 'checkbox',
  value: coffeeOrder.emailAddress
});

var description = coffeeOrder.size + ' ';
if(coffeeOrder.flavor){
  description += coffeeOrder.flavor + ' ';
}
description += coffeeOrder.coffee + ', ';
description += ' (' + coffeeOrder.emailAddress + ')';
description += ' [' + coffeeOrder.strength + 'x]';

$label.append($checkbox);
$label.append(description);
$div.append($label);

this.$element = $div;

}

BlockquoteApp.CheckList = CheckList;
window.App = App;
})(window);