Skip to content

Commit 76f47d7

Browse files
SearchEditor: Enhance to configure user-defined condition metadata
Completer.js: Identify and populate `metadata` fields
1 parent f5b19dc commit 76f47d7

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

asset/js/widget/Completer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,8 @@ define(["../notjQuery"], function ($) {
279279
input.value = value;
280280

281281
for (let name in data) {
282-
let dataElement = input.form[input.name + '-' + name];
282+
let dataElement = input.form[input.name + '-' + name]
283+
?? input.form[input.name + '-metadata-' + name];
283284
if (typeof dataElement !== 'undefined') {
284285
if (dataElement instanceof RadioNodeList) {
285286
dataElement = dataElement[dataElement.length - 1];

src/Control/SearchEditor.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ class SearchEditor extends Form
5555
/** @var bool */
5656
protected $cleared = false;
5757

58+
/** @var string[] Additional `metadata` fields for the condition */
59+
protected array $metadataFields = [];
60+
5861
/**
5962
* Set the filter query string to populate the form with
6063
*
@@ -95,6 +98,22 @@ public function setSuggestionUrl(Url $url)
9598
return $this;
9699
}
97100

101+
/**
102+
* Set additional `metadata` fields for the condition
103+
*
104+
* The value of these fields is populated to condition's `metadata`
105+
*
106+
* @param array $fields
107+
*
108+
* @return $this
109+
*/
110+
public function setMetadataFields(array $fields): static
111+
{
112+
$this->metadataFields = $fields;
113+
114+
return $this;
115+
}
116+
98117
/**
99118
* Get the query string parser being used
100119
*
@@ -551,6 +570,19 @@ protected function createCondition(Filter\Condition $condition, $identifier)
551570
}]
552571
]);
553572

573+
$metadataFields = new HtmlDocument();
574+
foreach ($this->metadataFields as $fieldNameSuffix) {
575+
$name = $identifier . '-column-metadata-' . $fieldNameSuffix;
576+
$columnMetaInput = $this->createElement('hidden', $name, [
577+
'value' => $condition->metaData()->get($fieldNameSuffix)
578+
]);
579+
$this->registerElement($columnMetaInput);
580+
581+
$condition->metaData()->set($fieldNameSuffix, $this->getValue($name));
582+
583+
$metadataFields->addHtml($columnMetaInput);
584+
}
585+
554586
$operatorInput = $this->createElement('select', $identifier . '-operator', [
555587
'options' => [
556588
'~' => '~',
@@ -588,6 +620,7 @@ protected function createCondition(Filter\Condition $condition, $identifier)
588620
$columnInput,
589621
$columnFakeInput,
590622
$columnSearchInput,
623+
$metadataFields,
591624
$operatorInput,
592625
$valueInput
593626
);

0 commit comments

Comments
 (0)