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 <f.ebner@proxmox.com>
This commit is contained in:
Fabian Ebner 2021-03-15 12:57:28 +01:00 committed by Thomas Lamprecht
parent f8d1d5ad9a
commit dcbc3b3ee9

View File

@ -36,12 +36,16 @@ Ext.define('PVE.form.BandwidthField', {
// for KiB set it to 'KiB' // for KiB set it to 'KiB'
backendUnit: undefined, backendUnit: undefined,
// allow setting 0 and using it as a submit value
allowZero: false,
items: [ items: [
{ {
xtype: 'numberfield', xtype: 'numberfield',
cbind: { cbind: {
name: '{name}', name: '{name}',
emptyText: '{emptyText}', emptyText: '{emptyText}',
allowZero: '{allowZero}',
}, },
minValue: 0, minValue: 0,
step: 1, step: 1,
@ -61,7 +65,9 @@ Ext.define('PVE.form.BandwidthField', {
this._transformed = true; 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); 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()); let v = this.processRawValue(this.getRawValue());
v = v.replace(this.decimalSeparator, '.'); v = v.replace(this.decimalSeparator, '.');
if (v === undefined) return null; if (v === undefined || v === '') {
// FIXME: make it configurable, as this only works if 0 === default return null;
if (v == 0 || v == 0.0) return null; }
if (Number(v) === 0) {
return this.allowZero ? 0 : null;
}
let fieldct = this.up('pveBandwidthField'); let fieldct = this.up('pveBandwidthField');
let vm = fieldct.getViewModel(); let vm = fieldct.getViewModel();