I have several questions after working through this challenge. Because of the asynchronous call with RemoteDataStore’s get method (using jQuery’s get method), it finally dawned on me that we can’t add this handler to formhandler.js like we have been doing. So I added it directly to validation.js and put this code below.
I am not sure why it is suggested to open a second browser. I did notice that after every character input, the server request was being made. So I finally added in the same check I added in isCompanyEmail so that we only make server request when the email has the right form.
-
Before I added this check to call get, I was able to submit with bad emails. So the original isCompanyEmail handler was no longer in effect. Now that I have this check, its back into effect. But I am repeating the regular expression check. So I am not sure how to avoid that? And how do we avoid overriding the original isCompanyEmail handler. It seems to me that the isCompanyEmail should be checked first and if that succeeds, then check if the email is already on the server.
-
Is there something else to do to optimize? What does a second window do for us? I didn’t get that part.
-
My emailInput is a jQuery object for the email input. It works fine with the .setCustomValidity method. But it does not work with other properties from the Constraint Validation API (here ). However, using querySelector (so not jQuery), we can. So is there a jQuery version of these properties? Why can we call the method but not the properties with the jQuery version of emailInput?
addEmailAvailableHandler: function (db) {
console.log(‘Setting duplicate email input handler for form’);
var emailInput = $(’[data-coffee-order=“email”]’);// for some reason .setCustomValidity works on jQuery version
// but .validity … properties does not work with jQuery version
var emailInputNojQuery = document.querySelector(’[data-coffee-order=“email”]’);var cb = function(serverResponse) {
var message = ‘’;
if (serverResponse === null) {
emailInput.setCustomValidity(message);
} else {
message = emailInput.val() + ’ already has an order!’;
emailInput.setCustomValidity(message);
} // end if/else// console.log(emailInput.validity); // undefined? why? console.log(emailInputNojQuery.validationMessage); console.log(emailInputNojQuery.validity); console.log(emailInputNojQuery.validity.customError);
} // end cb(serverResponse)
emailInput.on(‘input’, function(event) {
var email = event.target.value;
if ( /.+@me.com$/.test(email) ) {
db.get(email, cb);
} // end if
});
},