Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

luci-base: add member allowduplicates to DynamicList #7558

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions modules/luci-base/htdocs/luci-static/resources/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -3863,6 +3863,17 @@ const CBIValue = CBIAbstractValue.extend(/** @lends LuCI.form.Value.prototype */
const CBIDynamicList = CBIValue.extend(/** @lends LuCI.form.DynamicList.prototype */ {
__name__: 'CBI.DynamicList',

/**
* Allows the underlying form controls to have multiple identical values.
*
* Default is `null`. If `true`, the underlying form value will
* not be checked for duplication.
*
* @name LuCI.form.DynamicList.prototype#allowduplicates
* @type boolean
* @default null
*/

/** @private */
renderWidget(section_id, option_index, cfgvalue) {
const value = (cfgvalue != null) ? cfgvalue : this.default;
Expand All @@ -3872,6 +3883,7 @@ const CBIDynamicList = CBIValue.extend(/** @lends LuCI.form.DynamicList.prototyp
const widget = new ui.DynamicList(items, choices, {
id: this.cbid(section_id),
sort: this.keylist,
allowduplicates: this.allowduplicates,
optional: this.optional || this.rmempty,
datatype: this.datatype,
placeholder: this.placeholder,
Expand Down
5 changes: 3 additions & 2 deletions modules/luci-base/htdocs/luci-static/resources/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -2424,7 +2424,7 @@ const UIDynamicList = UIElement.extend(/** @lends LuCI.ui.DynamicList.prototype
exists = true;
});

if (!exists) {
if (this.options.allowduplicates || !exists) {
const ai = dl.querySelector('.add-item');
ai.parentNode.insertBefore(new_item, ai);
}
Expand Down Expand Up @@ -2505,7 +2505,8 @@ const UIDynamicList = UIElement.extend(/** @lends LuCI.ui.DynamicList.prototype
return;

sbIn.setValues(sbEl, null);
sbVal.element.setAttribute('unselectable', '');
if (!this.options.allowduplicates)
sbVal.element.setAttribute('unselectable', '');
systemcrash marked this conversation as resolved.
Show resolved Hide resolved

if (sbVal.element.hasAttribute('created')) {
sbVal.element.removeAttribute('created');
Expand Down
Loading