Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backbone-validation flatten exception on models containing selectors in latest Chrome #233

Closed
sergey-dev opened this issue Jul 15, 2014 · 1 comment

Comments

@sergey-dev
Copy link

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
          ) {
...
@chiefGui
Copy link
Collaborator

Fixed by #260.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants