[pve-devel] [PATCH v2 manager 5/5] ui/UplaodToStorage: check file extension

Dominik Csapak d.csapak at proxmox.com
Mon Aug 2 16:40:23 CEST 2021


comment inline

On 7/22/21 15:06, Lorenz Stechauner wrote:
> Signed-off-by: Lorenz Stechauner <l.stechauner at proxmox.com>
> ---
>   www/manager6/window/UploadToStorage.js | 17 +++++++++++++++++
>   1 file changed, 17 insertions(+)
> 
> diff --git a/www/manager6/window/UploadToStorage.js b/www/manager6/window/UploadToStorage.js
> index c63de16a..3f4596ce 100644
> --- a/www/manager6/window/UploadToStorage.js
> +++ b/www/manager6/window/UploadToStorage.js
> @@ -156,6 +156,20 @@ Ext.define('PVE.window.UploadToStorage', {
>   		checksum.allowBlank = false;
>   	    }
>   	},
> +
> +	filenameChange: function(field) {
> +	    const view = this.getView();
> +	    const filename = field.getValue();

as before, this is available as second parameter.

> +	    for (let ext of view.acceptedExtensions[view.content]) {
> +		if (filename.endsWith(ext)) {
> +		    field.setValidation();
> +		    field.validate();
> +		    return;
> +		}
> +	    }
> +	    field.setValidation("wrong file extension");
> +	    field.validate();
> +	},

would that not fit better in the 'validator' function?

>       },
>   
>       items: [
> @@ -193,6 +207,9 @@ Ext.define('PVE.window.UploadToStorage', {
>   		    bind: {
>   			value: '{filename}',
>   		    },
> +		    listeners: {
> +			change: 'filenameChange',
> +		    },
>   		},
>   		{
>   		    xtype: 'displayfield',
> 






More information about the pve-devel mailing list