Skip to content

Commit

Permalink
Merge pull request #2006 from scireum/feature/jvo/readonly-lookup-val…
Browse files Browse the repository at this point in the history
…ue-elements
  • Loading branch information
jakobvogel authored Jun 14, 2024
2 parents 64fb784 + 64fcb72 commit 979647c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
15 changes: 12 additions & 3 deletions src/main/resources/default/taglib/t/lookupValue.html.pasta
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,19 @@
<i:arg name="allowCustomEntries" type="boolean" default="@value.acceptsCustomValues()"/>
<i:arg name="class" type="String" default="" description="Lists additional CSS classes to apply to the field."/>


<i:pragma name="inline" value="true"/>
<i:pragma name="description" value="Renders a dropdown field for a LookupValue field"/>


<t:singleSelect name="@name" label="@label" help="@help" optional="@optional" readonly="@readonly" id="@id"
allowCustomEntries="@allowCustomEntries" class="@class"
<t:singleSelect name="@name"
label="@label"
help="@help"
optional="@optional"
readonly="@readonly"
id="@id"
allowCustomEntries="@allowCustomEntries"
class="@class"
suggestionUri="@apply('/system/lookuptable/autocomplete/%s/%s/%s', table, value.getDisplay(), value.getExtendedDisplay())">
<i:block name="addon">
<i:if test="showSelectionButton">
Expand All @@ -38,7 +45,9 @@
tableName: '___table',
labelFormat: '___value.getDisplay()',
codeCallback: function (code, name) {
autocomplete.val({value: code, text: name});
@if (!readonly) {
autocomplete.val({value: code, text: name});
}
}
});
}
Expand Down
26 changes: 19 additions & 7 deletions src/main/resources/default/taglib/t/lookupValues.html.pasta
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<i:arg name="helpKey" type="String" default=""/>
<i:arg name="help" type="String" default="@i18n(helpKey)"/>
<i:arg name="readonly" type="boolean" default="false"/>
<i:arg name="showSelectionButton" type="boolean" default="true"/>
<i:arg name="table" type="String" default="@values.getTableName()"/>
<i:arg name="id" type="String" default="@generateId('singleselect-%s')"/>
<i:arg name="class" type="String" default="" description="Lists additional CSS classes to apply to the field."/>
Expand All @@ -14,27 +15,38 @@
<i:pragma name="description" value="Renders a multiselect dropdown field for LookupValues field"/>


<t:multiSelect name="@name" label="@label" help="@help" readonly="@readonly" id="@id"
allowCustomEntries="@values.acceptsCustomValues()" class="@class"
<t:multiSelect name="@name"
label="@label"
help="@help"
readonly="@readonly"
id="@id"
allowCustomEntries="@values.acceptsCustomValues()"
class="@class"
suggestionUri="@apply('/system/lookuptable/autocomplete/%s/%s/%s', table, values.getDisplay(), values.getExtendedDisplay())">
<i:block name="addon">
<a class="btn btn-outline-secondary" id="@id-addon"><i class="fa-solid fa-bolt"></i></a>
<i:if test="showSelectionButton">
<a class="btn btn-outline-secondary" id="@id-addon"><i class="fa-solid fa-bolt"></i></a>
</i:if>
</i:block>
<i:block name="script">
<i:if test="showSelectionButton">
const helper = document.getElementById('___id-addon');
helper.addEventListener('click', function () {
new LookupTableInfo({
tableName: '___table',
labelFormat: '___values.getDisplay()',
codeCallback: function (code, name) {
if (!autocomplete.val().includes(code)) {
autocomplete.addToken({value: code, text: name});
} else {
autocomplete.select.removeTokenWithText(name);
@if (!readonly) {
if (!autocomplete.val().includes(code)) {
autocomplete.addToken({value: code, text: name});
} else {
autocomplete.select.removeTokenWithText(name);
}
}
}
});
});
</i:if>
</i:block>
<i:for var="tuple"
type="Tuple"
Expand Down

0 comments on commit 979647c

Please sign in to comment.