alchemication
alchemication

Reputation: 5324

Backbone.js ModelBinder change default event to keyup

During development of my Backbone.js app - I've noticed a lot of boilerplate code in my views, so I've decided to search for a Model Binder library,

Best option seems to be: Backbone.ModelBinder

...but the problem is that it doesn't allow me to switch from the default "blur" event into "keyup" for the content-editable inputs.

I've tried to modify the source code of the library, but it kind-of ignores my 2 changes from "blur" into "keyup" for content-editable fields and still falls back onto the "blur" event.

Has anyone experienced similar issue or perhaps can help me out with this?

Thanks a lot.

Upvotes: 1

Views: 771

Answers (1)

Ingro
Ingro

Reputation: 2841

Where did you changed that in the source code?

I've tried to edit the two lines as seen in this commit and it works...

    _bindViewToModel:function () {
        $(this._rootEl).delegate('', 'change keyup', this._onElChanged);
        // The change event doesn't work properly for contenteditable elements - but blur does
        $(this._rootEl).delegate('[contenteditable]', 'blur keyup', this._onElChanged);
    },

    _unbindViewToModel: function(){
        if(this._rootEl){
            $(this._rootEl).undelegate('', 'change keyup', this._onElChanged);
            $(this._rootEl).undelegate('[contenteditable]', 'blur keyup', this._onElChanged);
        }
    },

Upvotes: 2

Related Questions