diff --git a/StringUtils.php b/StringUtils.php index 4b2ef1c..91c287e 100644 --- a/StringUtils.php +++ b/StringUtils.php @@ -8,7 +8,7 @@ class StringUtils extends \ExternalModules\AbstractExternalModule { - const annotation = ["@TOLOWER", "@TOUPPER", "@SUBSTR", "@LTRIM", "@RTRIM", "@TRIM", "@STRLEN", "@INDEXOF"]; + const annotation = ["@TOLOWER", "@TOUPPER", "@SUBSTR", "@LTRIM", "@RTRIM", "@TRIM", "@STRLEN", "@INDEXOF", "@CONCAT"]; public function redcap_data_entry_form($project_id, $record, $instrument, $event_id, $group_id, $repeat_instance) @@ -58,7 +58,7 @@ public function getFieldNames($project_id) public function showWarnings(array $listeners, array $fieldNames, array $warnings) { foreach ($listeners as $sourceField => $code) { - if (!in_array($sourceField, $fieldNames)) { + if (!in_array($sourceField, $fieldNames)) { echo '
The following field is used by cannot be found: ' . $sourceField . '
'; } } @@ -123,10 +123,22 @@ public function getListenersFromAnot($field_annotation, $field, $annotation, arr $warnings [] = 'For field: ' . $destinationField . ' ' . $selectedFields[2] . ' is not numeric'; } if (!in_array($selectedFields[0], $fieldNames)) { - $warnings [] = 'For field: ' . $destinationField . ' ' . $selectedFields[0] . ' is not fields.'; + $warnings [] = 'For field: ' . $destinationField . ' ' . $selectedFields[0] . ' is not a field.'; } $listeners[$selectedFields[0]] .= '$("input[name=\'' . $destinationField . '\']").val($("input[name=\'' . $selectedFields[0] . '\']").val().substr(' . $selectedFields[1] . ', ' . $selectedFields[2] . '));'; break; + case "@CONCAT": + $sourceFieldsConcat = []; + $explodedSource = explode (",", $sourceField); + foreach($explodedSource as $explodedPiece) + { + $sourceFieldsConcat []= "$(\"input[name='$explodedPiece']\").val()"; + } + foreach($explodedSource as $explodedPiece) + { + $listeners[$explodedPiece] .= '$("input[name=\'' . $destinationField . '\']").val('.implode("+",$sourceFieldsConcat).');'; + } + break; default: break; } diff --git a/howto.html b/howto.html index 1e8cec5..3e191fb 100644 --- a/howto.html +++ b/howto.html @@ -100,6 +100,14 @@

How to use the StringUti Takes a part of a string from start, returns the specified number of characters (length). start and length must be valid integers. + + + @CONCAT=field1,field2,field3,... + + + Concatenates other text fields into one field. The fields must be valid field names. The list can contain any amount of fields. The list of fields MUST NOT contain spaces. + +