Skip to content

Commit

Permalink
add modelAttr param to format callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
delambo committed Sep 20, 2012
1 parent 12a786c commit 712feca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions backbone.stickit.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
getVal = function(field) {
var val = config.escape ? model.escape(field) : model.get(field);
if (_.isUndefined(val)) val = '';
return format ? applyViewFn(self, format, val) : val;
return format ? applyViewFn(self, format, val, modelAttr) : val;
};

// Setup the attributes configuration.
Expand All @@ -60,7 +60,7 @@
observed = attrConfig.observe || modelAttr,
updateAttr = function() {
var val;
if (attrConfig.format) val = applyViewFn(self, attrConfig.format, model.get(observed));
if (attrConfig.format) val = applyViewFn(self, attrConfig.format, model.get(observed), observed);
else val = model.get(observed);
// If it is a class then we need to remove the last value and add the new.
if (attrConfig.name == 'class') {
Expand Down
10 changes: 5 additions & 5 deletions test/bindData.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,13 @@ $(document).ready(function() {
view.bindings = {
'#test5': {
modelAttr: 'water',
format: function(val) { return '_' + val; }
format: function(val, modelAttr) { return '_' + val + '_' + modelAttr; }
}
};

$('#qunit-fixture').html(view.render().el);

equal(view.$('#test5').text(), '_fountain');
equal(view.$('#test5').text(), '_fountain_water');
});

test('bindings:readonly', function() {
Expand Down Expand Up @@ -411,17 +411,17 @@ $(document).ready(function() {
modelAttr: 'water',
attributes: [{
name: 'data-name',
format: function() { return this.model.get('water') + '-ralph'; }
format: function(val, modelAttr) { return '_' + val + '_' + modelAttr; }
}]
}
};

$('#qunit-fixture').html(view.render().el);

equal(view.$('#test5').attr('data-name'), 'fountain-ralph');
equal(view.$('#test5').attr('data-name'), '_fountain_water');

model.set('water', 'evian');
equal(view.$('#test5').attr('data-name'), 'evian-ralph');
equal(view.$('#test5').attr('data-name'), '_evian_water');
});

test('bindings:attributes:observe', function() {
Expand Down

0 comments on commit 712feca

Please sign in to comment.