diff --git a/CHANGELOG.md b/CHANGELOG.md index 0debc87..4812a4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,16 @@ # Change Log All notable changes to the Auto-Populate Fields project will be documented in this file. + +## [2.6.0] - 2020-10-09 +### Changed +- Upgrade test_project to enable surveys (Kyle Chesney) +- Explicitly check that field to hide is present in a form prevents bug on multipage forms in surveys. (Kyle Chesney) + +### Added +- Add support for Surveys (Kyle Chesney) + + ## [2.5.2] - 2020-08-21 ### Changed - Added a element check to prevent attempting to hide nonexistent elements (James Pence) diff --git a/ExternalModule.php b/ExternalModule.php index 1ebc806..4d9f31f 100644 --- a/ExternalModule.php +++ b/ExternalModule.php @@ -17,6 +17,7 @@ * ExternalModule class for Auto Populate Fields. */ class ExternalModule extends AbstractExternalModule { + private $survey_APF_fields = []; /** * @inheritdoc @@ -30,7 +31,7 @@ function redcap_every_page_top($project_id) { if (PAGE == 'Design/online_designer.php') { $this->includeJs('js/helper.js'); } - elseif ( (PAGE == 'DataEntry/index.php' || PAGE == 'surveys/index.php') && !empty($_GET['id'])) { + elseif ( (PAGE == 'DataEntry/index.php' || PAGE == 'surveys/index.php') && !empty($_GET['id']) ) { if (!$this->currentFormHasData()) { $this->setDefaultValues(); } @@ -41,6 +42,20 @@ function redcap_every_page_top($project_id) { } } + function redcap_survey_page_top($project_id) { + if ( !$this->getProjectSetting('use_in_survey') ) return; + global $elements; + // set the action_tag_class as it would be in the DataEntry context + foreach( $elements as &$element) { + $i = array_search($element['name'], $this->survey_APF_fields); + if ( $i !== false ) { + $element['action_tag_class'] = '@DEFAULT'; + unset($this->survey_APF_fields[$i]); + if ( empty($this->survey_APF_fields) ) break; + } + } + } + /** * Extends @DEFAULT action tag. * @@ -229,6 +244,7 @@ function setDefaultValues() { // The first non empty default value wins! $misc = $this->overrideActionTag('@DEFAULT', $default_value, $misc); $aux_metadata[$field_name]['misc'] = $misc; + array_push($this->survey_APF_fields, $field_name); break; } diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..e70b452 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +2.6.0 diff --git a/config.json b/config.json index 032ef61..a8943b2 100644 --- a/config.json +++ b/config.json @@ -7,6 +7,7 @@ }, "permissions": [ "redcap_every_page_top", + "redcap_survey_page_top", "redcap_module_system_enable", "redcap_module_system_change_version" ], @@ -28,6 +29,11 @@ } ], "project-settings": [ + { + "key": "use_in_survey", + "name": "Enable Auto Populate Fields on survey pages", + "type": "checkbox" + }, { "key": "chronological_previous_event", "name": "Enable chronological previous event detection (useful when the events are not necessarily arranged in a chronological order)", diff --git a/examples/test_project.xml b/examples/test_project.xml index 499e7d5..7a62bee 100644 --- a/examples/test_project.xml +++ b/examples/test_project.xml @@ -1,21 +1,36 @@ - - + + - auto_populate_fields test - This file contains the metadata, events, and data for REDCap project "auto_populate_fields test". - auto_populate_fields test + APF - multisurvey + This file contains the metadata, events, and data for REDCap project "APF - multisurvey". + APF - multisurvey 1 0 - 0 + 1 - 2 - 7 + 0 + + + + + + + + - + @@ -66,6 +81,7 @@ + @@ -73,19 +89,24 @@ - + - + - + + + + + + @@ -106,7 +127,8 @@ - + + @@ -116,7 +138,8 @@ - + + @@ -127,7 +150,8 @@ - + + @@ -137,6 +161,15 @@ Study ID + + Survey Identifier + + + Survey Timestamp + + + Survey Timestamp + Date subject signed consent @@ -165,6 +198,9 @@ Complete? + + Survey Timestamp + dropdown from previous @@ -189,6 +225,9 @@ Complete? + + Survey Timestamp + birthdate_mdy @@ -211,6 +250,9 @@ Complete? + + Survey Timestamp + Show choice 2? @@ -238,15 +280,15 @@ 5-10 6-15 - + Checked Unchecked - + Checked Unchecked - + Checked Unchecked @@ -272,7 +314,7 @@ - + @@ -297,7 +339,7 @@ - + @@ -309,7 +351,7 @@ - + @@ -317,11 +359,11 @@ - + - + @@ -330,38 +372,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + \ No newline at end of file diff --git a/js/default_when_visible.js b/js/default_when_visible.js index eebce37..b3f52c6 100644 --- a/js/default_when_visible.js +++ b/js/default_when_visible.js @@ -33,7 +33,10 @@ autoPopulateFields.defaultWhenVisible.init = function() { } } catch ( e ) { - evalLogicSubmit( fieldName, false, false ); + // field specified in equation was not present + if ( document.getElementsByName(fieldName).length !== 0 ) { // must check if fieldName is present on multipage forms + evalLogicSubmit( fieldName, false, false ); + } } });