From 538ebe4a84d99ec19bf8d25bcf63131e3c220d94 Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Fri, 18 Nov 2016 10:13:37 +0100 Subject: [PATCH] add kvcombobox validator this enables validation of all kvcomboboxes, including multiselect Signed-off-by: Dominik Csapak --- www/manager6/form/KVComboBox.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/www/manager6/form/KVComboBox.js b/www/manager6/form/KVComboBox.js index beafed07..a135f4d9 100644 --- a/www/manager6/form/KVComboBox.js +++ b/www/manager6/form/KVComboBox.js @@ -33,6 +33,28 @@ Ext.define('PVE.form.KVComboBox', { return data; }, + validator: function(val) { + var me = this; + + if (me.editable || val === null || val === '') { + return true; + } + + if (me.comboItems) { + var values = me.multiSelect ? val.split(me.delimiter) : [val]; + var items = Ext.Array.pluck(me.comboItems, 1); + if (Ext.Array.every(values, function(value) { + return Ext.Array.contains(items, value); + })) { + return true; + } + } + + // returns a boolean or string + /*jslint confusion: true */ + return "value '" + val + "' not allowed!"; + }, + initComponent: function() { var me = this;