Skip to content

Commit

Permalink
Recalculate form fields when page is turned (#3920)
Browse files Browse the repository at this point in the history
Attempt to work around jr:choice-name() performance issues by reclalculating
fields one more time on form load, and on every page change.  If choice-name()s
only reference fields on different pages, or vice versa, then maybe they will
become usable.

Issue: #3870
  • Loading branch information
alxndrsn authored and garethbowen committed Sep 20, 2017
1 parent d9ff646 commit 9a74901
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 25 deletions.
4 changes: 0 additions & 4 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,6 @@ module.exports = function(grunt) {
// https://github.com/medic/medic-webapp/issues/2797
'patch node_modules/pouchdb-adapter-idb/lib/index.js < patches/pouchdb-ignore-safari-check.patch',

// patch enketo to support cascading of jr:choice-name() update results
// https://github.com/medic/medic-webapp/issues/3804
'patch node_modules/enketo-core/src/js/output.js < patches/3804_jr-choice-name.patch',

// patch enketo's bootstrap-datepicker dependency so that sass compiles properly
'patch node_modules/enketo-core/src/widget/date/datepicker-extended.scss < patches/enketo-datepicker-extended-sass-import.patch',
];
Expand Down
20 changes: 0 additions & 20 deletions patches/3804_jr-choice-name.patch

This file was deleted.

7 changes: 7 additions & 0 deletions static/js/services/enketo.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ angular.module('inboxServices').service('Enketo',
window.history.replaceState({ enketo_page_number: 0 }, '');
overrideNavigationButtons(form, wrapper);
addPopStateHandler(form, wrapper);
forceRecalculate(form);

return form;
});
Expand All @@ -272,6 +273,7 @@ angular.module('inboxServices').service('Enketo',
if(typeof newPageIndex === 'number') {
window.history.pushState({ enketo_page_number: newPageIndex }, '');
}
forceRecalculate(form);
});
return false;
});
Expand All @@ -280,6 +282,7 @@ angular.module('inboxServices').service('Enketo',
.off('.pagemode')
.on('click.pagemode', function() {
window.history.back();
forceRecalculate(form);
return false;
});
};
Expand Down Expand Up @@ -464,6 +467,10 @@ angular.module('inboxServices').service('Enketo',
});
};

var forceRecalculate = function(form) {
form.calc.update();
};

this.save = function(formInternalId, form, docId) {
return $q.resolve(form.validate())
.then(function(valid) {
Expand Down
3 changes: 2 additions & 1 deletion tests/karma/unit/services/enketo.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ describe('Enketo service', function() {

window.EnketoForm = EnketoForm;
EnketoForm.returns({
init: enketoInit
init: enketoInit,
calc: { update: function() {} }
});

XmlForm.returns(KarmaUtils.mockPromise(null, { id: 'abc' }));
Expand Down

0 comments on commit 9a74901

Please sign in to comment.