diff --git a/StringUtils.php b/StringUtils.php index 0719f76..99eca74 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", "@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) @@ -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); diff --git a/howto.html b/howto.html index a47381c..4e22a1b 100644 --- a/howto.html +++ b/howto.html @@ -100,6 +100,15 @@

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. + + + @LEFT=sourcefieldnamehere,length + + + Returns the length number of characters from the start of a text string. + + + @RIGHT=sourcefieldnamehere,length