Skip to content

Commit

Permalink
Added left function.
Browse files Browse the repository at this point in the history
  • Loading branch information
denshade committed Dec 3, 2019
1 parent 0fa32b5 commit 3a5b3c1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
12 changes: 11 additions & 1 deletion 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", "@CONCAT", "@RIGHT"];
const annotation = ["@TOLOWER", "@TOUPPER", "@SUBSTR", "@LTRIM", "@RTRIM", "@TRIM", "@STRLEN", "@INDEXOF", "@CONCAT", "@RIGHT", "@LEFT"];


public function redcap_data_entry_form($project_id, $record, $instrument, $event_id, $group_id, $repeat_instance)
Expand Down Expand Up @@ -137,6 +137,16 @@ public function getListenersFromAnot($field_annotation, $field, $annotation, arr
}
$listeners[$selectedFields[0]] .= '$("input[name=\'' . $destinationField . '\']").val($("input[name=\'' . $selectedFields[0] . '\']").val().substr($("input[name=\'' . $selectedFields[0] . '\']").val().length - ' . $selectedFields[1] . ', $("input[name=\'' . $selectedFields[0] . '\']").val().length));';
break;
case "@LEFT":
$selectedFields = explode(",", $sourceField);
if (!is_numeric($selectedFields[1])) {
$warnings [] = 'For field: ' . $destinationField . ' ' . $selectedFields[1] . ' is not numeric';
}
if (!in_array($selectedFields[0], $fieldNames)) {
$warnings [] = 'For field: ' . $destinationField . ' ' . $selectedFields[0] . ' is not a field.';
}
$listeners[$selectedFields[0]] .= '$("input[name=\'' . $destinationField . '\']").val($("input[name=\'' . $selectedFields[0] . '\']").val().substr(0, '.$selectedFields[1].'));';
break;
case "@CONCAT":
$sourceFieldsConcat = [];
$explodedSource = explode (",", $sourceField);
Expand Down
9 changes: 9 additions & 0 deletions howto.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ <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>
@LEFT=sourcefieldnamehere,length
</td>
<td>
Returns the <code>length</code> number of characters from the start of a text string.
</td>
</tr>
<tr>
<tr>
<td>
@RIGHT=sourcefieldnamehere,length
Expand Down

0 comments on commit 3a5b3c1

Please sign in to comment.