-
Notifications
You must be signed in to change notification settings - Fork 297
Description
Spend a while debugging the culprit of an strange exception in Chrome, which doesn't happen in other browsers:
Uncaught InvalidStateError: Failed to read the 'selectionDirection' property from 'HTMLInputElement': The input element's type ('submit') does not support selection.
Debugging and catching an exception showed me off the line this.model.isValid(true) and method flatten() within the backbone-validation-amd.js module.
Prehistory how it happens and how to reproduce:
there was the need to store one of jQuery selectors within the backbone.model attributes. When flatten() method itterates
_.each(obj, function(val, key) {
if(obj.hasOwnProperty(key)) {
...
it goes through the whole structure of jQuery selector and nested properties. For my bad/good luck, this selector contained the submit button, which throws InvalidStateError exception on iteration of properties in latest Chrome, though it works great in FF and Opera browsers at the same time.
The solution is really simple, to exlude the case when model attributes for some reason contain selectors, just add another check to the list of checks to the flatten(), at line 80:
...
val instanceof Backbone.Collection ||
val instanceof jQuery) // <=== here
) {
...