Skip to content

Commit

Permalink
feat(dropdownfield): allow regex comparison
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry committed Feb 17, 2021
1 parent 2de33ed commit 9fd8c1a
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion inc/field/dropdownfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,18 @@ public function lessThan($value): bool {
}

public function regex($value): bool {
throw new ComparisonException('Meaningless comparison');
$value = html_entity_decode($value);
$itemtype = $this->getSubItemtype($this->question->fields['values']);
$dropdown = new $itemtype();
if (!$dropdown->getFromDB($this->value)) {
throw new ComparisonException('Item not found for comparison');
}
if ($dropdown instanceof CommonTreeDropdown) {
$fieldValue = $dropdown->getField($dropdown->getCompleteNameField());
} else {
$fieldValue = $dropdown->getField($dropdown->getNameField());
}
return preg_match($value, Toolbox::stripslashes_deep($fieldValue)) ? true : false;
}

public function parseAnswerValues($input, $nonDestructive = false): bool {
Expand Down

0 comments on commit 9fd8c1a

Please sign in to comment.