Skip to content

Commit

Permalink
Added logic to calc JS so we re-calc when a group an observed element…
Browse files Browse the repository at this point in the history
… is in is added or removed. Useful if (say) keeping a running total of sub-totals in a repeat.
  • Loading branch information
cheesegrits committed Mar 2, 2017
1 parent d9de958 commit e3143f7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion plugins/fabrik_element/calc/calc-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 21 additions & 2 deletions plugins/fabrik_element/calc/calc.js
Expand Up @@ -11,6 +11,7 @@ define(['jquery', 'fab/element'], function (jQuery, FbElement) {
initialize: function (element, options) {
this.setPlugin('calc');
this.parent(element, options);
this.observeGroupIds = [];
},

attachedToForm: function () {
Expand All @@ -35,6 +36,19 @@ define(['jquery', 'fab/element'], function (jQuery, FbElement) {
}
}.bind(this));
}

Fabrik.addEvent('fabrik.form.group.duplicate.end', function(form, event, groupId) {
if (jQuery.inArray(groupId, this.observeGroupIds) !== -1) {
this.calc();
}
}.bind(this));

Fabrik.addEvent('fabrik.form.group.delete.end', function(form, event, groupId) {
if (jQuery.inArray(groupId, this.observeGroupIds) !== -1) {
this.calc();
}
}.bind(this));

this.parent();
},

Expand Down Expand Up @@ -70,10 +84,15 @@ define(['jquery', 'fab/element'], function (jQuery, FbElement) {
o2 = o + '_' + v2;
if (this.form.formElements[o2]) {
// $$$ hugh - think we can add this one as sticky ...
this.form.formElements[o2].addNewEvent(this.form.formElements[o2].getChangeEvent(),
this.form.formElements[o2].addNewEvent(
this.form.formElements[o2].getChangeEvent(),
function (e) {
this.calc(e);
}.bind(this));
}.bind(this)
);
if (jQuery.inArray(k, this.observeGroupIds) === -1) {
this.observeGroupIds.push(k);
}
}
}
}.bind(this));
Expand Down

0 comments on commit e3143f7

Please sign in to comment.