From dcbc3b3ee976c44f62385548054fdc77dd7a54e6 Mon Sep 17 00:00:00 2001 From: Fabian Ebner Date: Mon, 15 Mar 2021 12:57:28 +0100 Subject: [PATCH] ui: bandwidth limit selector: make it possible to allow zero The initial value is '' and in getSubmitValue(), previously the branch if (v == 0 || v == 0.0) return null; was taken, because of the lax '==' comparision. Make sure we still return null for '' by explicitly checking for it. Signed-off-by: Fabian Ebner --- www/manager6/form/BandwidthSelector.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/www/manager6/form/BandwidthSelector.js b/www/manager6/form/BandwidthSelector.js index 4ae52f9d..6f564fb8 100644 --- a/www/manager6/form/BandwidthSelector.js +++ b/www/manager6/form/BandwidthSelector.js @@ -36,12 +36,16 @@ Ext.define('PVE.form.BandwidthField', { // for KiB set it to 'KiB' backendUnit: undefined, + // allow setting 0 and using it as a submit value + allowZero: false, + items: [ { xtype: 'numberfield', cbind: { name: '{name}', emptyText: '{emptyText}', + allowZero: '{allowZero}', }, minValue: 0, step: 1, @@ -61,7 +65,9 @@ Ext.define('PVE.form.BandwidthField', { this._transformed = true; } - if (v == 0) v = undefined; + if (Number(v) === 0 && !this.allowZero) { + v = undefined; + } return Ext.form.field.Text.prototype.setValue.call(this, v); }, @@ -69,9 +75,13 @@ Ext.define('PVE.form.BandwidthField', { let v = this.processRawValue(this.getRawValue()); v = v.replace(this.decimalSeparator, '.'); - if (v === undefined) return null; - // FIXME: make it configurable, as this only works if 0 === default - if (v == 0 || v == 0.0) return null; + if (v === undefined || v === '') { + return null; + } + + if (Number(v) === 0) { + return this.allowZero ? 0 : null; + } let fieldct = this.up('pveBandwidthField'); let vm = fieldct.getViewModel();