Skip to content

Commit

Permalink
Added concat.
Browse files Browse the repository at this point in the history
  • Loading branch information
denshade committed Dec 3, 2019
1 parent b5ea899 commit 875f146
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
18 changes: 15 additions & 3 deletions StringUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 '<div class="alert">The following field is used by cannot be found: ' . $sourceField . '</div>';
}
}
Expand Down Expand Up @@ -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;
}
Expand Down
8 changes: 8 additions & 0 deletions howto.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ <h1><span class="glyphicon glyphicon-info-sign"></span> How to use the StringUti
Takes a part of a string from <code>start</code>, returns the specified number of characters (<code>length</code>). <code>start</code> and <code>length</code> must be valid integers.
</td>
</tr>
<tr>
<td>
@CONCAT=field1,field2,field3,...
</td>
<td>
Concatenates other <b>text</b> 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.
</td>
</tr>
</tbody>
</table>
</div>
Expand Down

0 comments on commit 875f146

Please sign in to comment.