[pve-devel] [PATCH manager] fix wizard validity check for options spanning multiple tabs

Dominik Csapak d.csapak at proxmox.com
Thu Feb 1 10:59:06 CET 2018


when changing the guest os, we changed the disk type
(e.g. ide for windows, scsi for linux, etc.)

but if the id was outside the allowed range (e.g. > 3 for ide)
we did not correctly enable/disable tabs

now we check all tabs until the highest already visited,
or until we detect a not valid tab

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 www/manager6/window/Wizard.js | 45 ++++++++++++++++++++++++++++++++-----------
 1 file changed, 34 insertions(+), 11 deletions(-)

diff --git a/www/manager6/window/Wizard.js b/www/manager6/window/Wizard.js
index fe5f8dd0..bc647dbd 100644
--- a/www/manager6/window/Wizard.js
+++ b/www/manager6/window/Wizard.js
@@ -41,6 +41,9 @@ Ext.define('PVE.window.Wizard', {
 	});
 	tabs[0].disabled = false;
 
+	var maxidx = 0;
+	var curidx = 0;
+
 	var check_card = function(card) {
 	    var valid = true;
 	    var fields = card.query('field, fieldcontainer');
@@ -163,7 +166,13 @@ Ext.define('PVE.window.Wizard', {
 	    me.down('#submit').setDisabled(!valid);    
 	    me.down('#back').setDisabled(tp.items.indexOf(newcard) == 0);
 
-	    var next = tp.items.indexOf(newcard) + 1;
+	    var idx = tp.items.indexOf(newcard);
+	    if (idx > maxidx) {
+		maxidx = idx;
+	    }
+	    curidx = idx;
+
+	    var next = idx + 1;
 	    var ntab = tp.items.getAt(next);
 	    if (valid && ntab && !newcard.onSubmit) {
 		ntab.enable();
@@ -231,16 +240,30 @@ Ext.define('PVE.window.Wizard', {
 	Ext.Array.each(me.query('field'), function(field) {
 	    var validcheck = function() {
 		var tp = me.down('#wizcontent');
-		var atab = tp.getActiveTab();
-		var valid = check_card(atab);
-		me.down('#next').setDisabled(!valid);
-		me.down('#submit').setDisabled(!valid);    
-		var next = tp.items.indexOf(atab) + 1;
-		var ntab = tp.items.getAt(next);
-		if (!valid) {
-		    disable_at(ntab);
-		} else if (ntab && !atab.onSubmit) {
-		    ntab.enable();
+
+		// check all tabs for validity
+		// since we might have changed a validity on another one
+		var i;
+		for (i = 0; i <= maxidx && i < tp.items.getCount(); i++) {
+		    var tab = tp.items.getAt(i);
+		    var valid = check_card(tab);
+
+		    // only set the buttons on the current panel
+		    if (i === curidx) {
+			me.down('#next').setDisabled(!valid);
+			me.down('#submit').setDisabled(!valid);
+		    }
+
+		    // if any panel is not valid disable from there,
+		    // else enable until we reach the rightmost
+		    // panel we already visited
+		    var ntab = tp.items.getAt(i + 1);
+		    if (!valid) {
+			disable_at(ntab);
+			return;
+		    } else if (ntab && !tab.onSubmit) {
+			ntab.enable();
+		    }
 		}
 	    };
 	    field.on('change', validcheck);
-- 
2.11.0





More information about the pve-devel mailing list