From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id F07986A8DB for ; Mon, 15 Mar 2021 12:57:33 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id E8ED5206D2 for ; Mon, 15 Mar 2021 12:57:33 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 13E14206B8 for ; Mon, 15 Mar 2021 12:57:33 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id AF99045530 for ; Mon, 15 Mar 2021 12:57:32 +0100 (CET) From: Fabian Ebner To: pve-devel@lists.proxmox.com Date: Mon, 15 Mar 2021 12:57:28 +0100 Message-Id: <20210315115729.24381-2-f.ebner@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210315115729.24381-1-f.ebner@proxmox.com> References: <20210315115729.24381-1-f.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.003 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH manager 2/3] ui: bandwidth limit selector: make it possible to allow zero X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 15 Mar 2021 11:57:34 -0000 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(); -- 2.20.1