Reputation: 5118
Is there any way of setting global setOptions
for Backbone.Stickit.js?
That way I can avoid having to set validate: true
as well as other custom options on every binding:
bindings = {
'.someEl': {
observe: 'prop1'
, setOptions: {
validate: true
}
}
, '.someOtherEl': {
observe: 'prop2'
, setOptions: {
validate: true
}
}
, '.yetAnotherEl': {
observe: 'prop3'
, setOptions: {
validate: true
}
}
};
I had seen some post about using the *
selector with .addHandler:
Backbone.Stickit.addHandler({
selector: '*',
setOptions: {validate: true}
});
But that didn't work for me.
I'm sure there's a simple way that I'm missing but for now my hack was to create a method that parses my property name:
function stickTo(propName, options) {
_.extend({observe: propName}, {setOptions: {validate: true}}, options);
}
...
bindings: {
'.someEl': stickTo('prop1')
}
stickTo sets all my default options and takes an optional parameter that overrides my defaults...
Upvotes: 2
Views: 1168
Reputation: 362
The handler should have worked. I setup a fiddle which logs the arguments of Model.set to the console, every time input changes:
Backbone.Stickit.addHandler({
selector: '*',
setOptions: {validate:true}
});
Upvotes: 1