Skip to content

Commit

Permalink
Recalculate form fields when page is turned
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 committed Sep 15, 2017
1 parent e35b8d5 commit ab448be
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 24 deletions.
4 changes: 0 additions & 4 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,6 @@ module.exports = function(grunt) {
// patch pouch to improve safari checks
// 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',
];
return patches.join(' && ');
}
Expand Down
20 changes: 0 additions & 20 deletions patches/3804_jr-choice-name.patch

This file was deleted.

12 changes: 12 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 @@ -268,10 +269,16 @@ angular.module('inboxServices').service('Enketo',
.off('.pagemode')
.on('click.pagemode', function() {
form.pages.next()
.then(function() {
forceRecalculate(form);
})
.then(function(newPageIndex) {
if(typeof newPageIndex === 'number') {
window.history.pushState({ enketo_page_number: newPageIndex }, '');
}
})
.then(function() {
forceRecalculate(form);
});
return false;
});
Expand All @@ -280,6 +287,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 +472,10 @@ angular.module('inboxServices').service('Enketo',
});
};

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

this.save = function(formInternalId, form, geolocation, docId) {
return $q.resolve(form.validate())
.then(function(valid) {
Expand Down

0 comments on commit ab448be

Please sign in to comment.