Improved UX of entity adding from part edit page.

This commit is contained in:
Jan Böhmer 2023-01-30 23:08:22 +01:00
parent 25be76b311
commit dc012b56a8
4 changed files with 31 additions and 20 deletions

View file

@ -34,21 +34,29 @@ export default class extends Controller {
this._emptyMessage = this.element.getAttribute("data-empty-message") ?? "";
const allowAdd = this.element.getAttribute("data-allow-add") === "true";
const addHint = this.element.getAttribute("data-add-hint") ?? "";
let settings = {
allowEmptyOption: true,
selectOnTab: true,
maxOptions: null,
create: allowAdd,
createFilter: /\D/, //Must contain a non-digit character, otherwise they would be recognized as DB ID
searchField: [
{field: "text", weight : 2},
{field: "parent", weight : 0.5},
{field: "path", weight : 1.0},
],
render: {
item: this.renderItem.bind(this),
option: this.renderOption.bind(this),
option_create: function(data, escape) {
return '<div class="create">Add <strong>' + escape(data.input) + '</strong>&hellip;&nbsp;' +
'<small class="text-muted float-end">(' + addHint +')</small>' +
'</div>';
},
}
};