diff options
author | Jo-Philipp Wich <jo@mein.io> | 2021-06-01 14:45:42 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2021-06-01 15:34:11 +0200 |
commit | f3f74bd0fe66b94a99a8d944b63dcd6bdd1b93c6 (patch) | |
tree | 8e41cd5e65cbe8584690f57a59487dc99b4ef795 /modules/luci-base/htdocs/luci-static/resources | |
parent | 671c94b034db9d7470d5f1e681b919158de205f6 (diff) |
luci-base: form.js: consider aliased options in AbstractValue.remove()
If different options point to the same underlying uci option, we must only
remove the uci value if none of the other alias options is active in order
to prevent inactive options (due to unsatisfied depends) removing the uci
value of active once on save.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'modules/luci-base/htdocs/luci-static/resources')
-rw-r--r-- | modules/luci-base/htdocs/luci-static/resources/form.js | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/modules/luci-base/htdocs/luci-static/resources/form.js b/modules/luci-base/htdocs/luci-static/resources/form.js index f7b4c64f8f..8fc8d3aca7 100644 --- a/modules/luci-base/htdocs/luci-static/resources/form.js +++ b/modules/luci-base/htdocs/luci-static/resources/form.js @@ -2035,10 +2035,32 @@ var CBIAbstractValue = CBIAbstractElement.extend(/** @lends LuCI.form.AbstractVa * The configuration section ID */ remove: function(section_id) { - return this.map.data.unset( - this.uciconfig || this.section.uciconfig || this.map.config, - this.ucisection || section_id, - this.ucioption || this.option); + var this_cfg = this.uciconfig || this.section.uciconfig || this.map.config, + this_sid = this.ucisection || section_id, + this_opt = this.ucioption || this.option; + + for (var i = 0; i < this.section.children.length; i++) { + var sibling = this.section.children[i]; + + if (sibling === this || sibling.ucioption == null) + continue; + + var sibling_cfg = sibling.uciconfig || sibling.section.uciconfig || sibling.map.config, + sibling_sid = sibling.ucisection || section_id, + sibling_opt = sibling.ucioption || sibling.option; + + if (this_cfg != sibling_cfg || this_sid != sibling_sid || this_opt != sibling_opt) + continue; + + if (!sibling.isActive(section_id)) + continue; + + /* found another active option aliasing the same uci option name, + * so we can't remove the value */ + return; + } + + this.map.data.unset(this_cfg, this_sid, this_opt); } }); |