Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/openwrt/luci.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2021-12-09 17:09:34 +0300
committerJo-Philipp Wich <jo@mein.io>2021-12-09 17:11:07 +0300
commitf5fbecf132b6c18141896b093935fb4c035ab33d (patch)
tree106d15f40cbc26d0d81ad4cd093dca4ba9de323c
parentac64c70436fff337ef7559b8ca7a2c54368200be (diff)
luci-base: form.js: implement AbstractValue.retain property
The new `retain` boolean property controls whether the related option value is purged from the configuration when the dependencies of the option are not satisifed. Ref: #5579 Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r--modules/luci-base/htdocs/luci-static/resources/form.js52
1 files changed, 36 insertions, 16 deletions
diff --git a/modules/luci-base/htdocs/luci-static/resources/form.js b/modules/luci-base/htdocs/luci-static/resources/form.js
index 2be5bbce86..312d83605d 100644
--- a/modules/luci-base/htdocs/luci-static/resources/form.js
+++ b/modules/luci-base/htdocs/luci-static/resources/form.js
@@ -1347,6 +1347,7 @@ var CBIAbstractValue = CBIAbstractElement.extend(/** @lends LuCI.form.AbstractVa
this.default = null;
this.size = null;
this.optional = false;
+ this.retain = false;
},
/**
@@ -1370,6 +1371,17 @@ var CBIAbstractValue = CBIAbstractElement.extend(/** @lends LuCI.form.AbstractVa
*/
/**
+ * If set to `true`, the underlying ui input widget value is not cleared
+ * from the configuration on unsatisfied depedencies. The default behavior
+ * is to remove the values of all options whose dependencies are not
+ * fulfilled.
+ *
+ * @name LuCI.form.AbstractValue.prototype#retain
+ * @type boolean
+ * @default false
+ */
+
+ /**
* Sets a default value to use when the underlying UCI option is not set.
*
* @name LuCI.form.AbstractValue.prototype#default
@@ -1979,30 +1991,38 @@ var CBIAbstractValue = CBIAbstractElement.extend(/** @lends LuCI.form.AbstractVa
* validation constraints.
*/
parse: function(section_id) {
- var active = this.isActive(section_id),
- cval = this.cfgvalue(section_id),
- fval = active ? this.formvalue(section_id) : null;
+ var active = this.isActive(section_id);
if (active && !this.isValid(section_id)) {
- var title = this.stripTags(this.title).trim();
- var error = this.getValidationError(section_id);
+ var title = this.stripTags(this.title).trim(),
+ error = this.getValidationError(section_id);
+
return Promise.reject(new TypeError(
_('Option "%s" contains an invalid input value.').format(title || this.option) + ' ' + error));
}
- if (fval != '' && fval != null) {
- if (this.forcewrite || !isEqual(cval, fval))
- return Promise.resolve(this.write(section_id, fval));
- }
- else {
- if (!active || this.rmempty || this.optional) {
- return Promise.resolve(this.remove(section_id));
+ if (active) {
+ var cval = this.cfgvalue(section_id),
+ fval = this.formvalue(section_id);
+
+ if (fval == null || fval == '') {
+ if (this.rmempty || this.optional) {
+ return Promise.resolve(this.remove(section_id));
+ }
+ else {
+ var title = this.stripTags(this.title).trim();
+
+ return Promise.reject(new TypeError(
+ _('Option "%s" must not be empty.').format(title || this.option)));
+ }
}
- else if (!isEqual(cval, fval)) {
- var title = this.stripTags(this.title).trim();
- return Promise.reject(new TypeError(_('Option "%s" must not be empty.').format(title || this.option)));
+ else if (this.forcewrite || !isEqual(cval, fval)) {
+ return Promise.resolve(this.write(section_id, fval));
}
}
+ else if (!this.retain) {
+ return Promise.resolve(this.remove(section_id));
+ }
return Promise.resolve();
},
@@ -3970,7 +3990,7 @@ var CBIFlagValue = CBIValue.extend(/** @lends LuCI.form.FlagValue.prototype */ {
else
return Promise.resolve(this.write(section_id, fval));
}
- else {
+ else if (!this.retain) {
return Promise.resolve(this.remove(section_id));
}
},