Skip to content

Commit

Permalink
Merge branch 'release/2.5.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
ChemiKyle committed Aug 21, 2020
2 parents bba0d74 + a47f286 commit 7b908a0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Change Log
All notable changes to the Auto-Populate Fields project will be documented in this file.

## [2.5.2] - 2020-08-21
### Changed
- Added a element check to prevent attempting to hide nonexistent elements (James Pence)
- add minimum REDCap version requirement of 8.0.3 (Kyle Chesney)

## [2.5.1] - 2020-04-24
### Changed
- Address issues found in REDCap 9.4.1 - 9.8.4 (Kyle Chesney)
Expand Down
3 changes: 3 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"name": "Auto Populate Fields",
"namespace": "AutoPopulateFields\\ExternalModule",
"description": "This module provides rich control of default values for data entry fields via a set of action tags. These action tags allow fields to be populated based on values from an ordered list of fields and static values. The fields can be read from the current event or the previous event in longitudinal projects. <strong><a href=\"https://github.com/ctsit/auto_populate_fields\">See full documentation here</a></strong>.",
"compatibility": {
"redcap-version-min": "8.0.3"
},
"permissions": [
"redcap_every_page_top",
"redcap_module_system_enable",
Expand Down
25 changes: 19 additions & 6 deletions js/default_when_visible.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
autoPopulateFields.defaultWhenVisible.init = function() {

// Extracting evalLogic function body.
var evalLogicBody = evalLogic.toString();
var evalLogicBody = evalLogicBody.slice(evalLogicBody.indexOf('{') + 1, evalLogicBody.lastIndexOf('}'));

var evalLogicBodyString = evalLogic.toString();

// To prevent style setting on nonexistent elements adding in a check for existence before trying to hide an element.
evalLogicBodyString = evalLogicBodyString.replace(
/document\.getElementById\(this_field\+\'\-tr\'\)\.style\.display=\'none\';/g,
'if ( document.getElementById(this_field + \'-tr\') != null ){ document.getElementById(this_field + \'-tr\').style.display = \'none\'; }'
);

evalLogicBody = evalLogicBodyString.slice(evalLogicBodyString.indexOf('{') + 1, evalLogicBodyString.lastIndexOf('}'));

// Changing evalLogic() function behavior: hide fields even when the message is not shown.
var target = 'var eraseIt = false;';
var replacement = 'var eraseIt = false; document.getElementById(this_field + \'-tr\').style.display = \'none\';';
var replacement = 'var eraseIt = false; if( document.getElementById(this_field + \'-tr\') != null ){ document.getElementById(this_field + \'-tr\').style.display = \'none\'; }';

// Overriding original function.
evalLogic = new Function('this_field', 'byPassEraseFieldPrompt', 'logic', evalLogicBody.replace(target, replacement));
Expand All @@ -19,8 +27,13 @@ autoPopulateFields.defaultWhenVisible.init = function() {
formSubmitDataEntry = function() {
$.each(autoPopulateFields.defaultWhenVisible.branchingEquations, function(fieldName, equation) {
// If equation result is false, erase field value.
if (!eval(equation)) {
evalLogicSubmit(fieldName, false, false);
try {
if ( !eval( equation ) ) {
evalLogicSubmit( fieldName, false, false );
}
}
catch ( e ) {
evalLogicSubmit( fieldName, false, false );
}
});

Expand Down

0 comments on commit 7b908a0

Please sign in to comment.