From bee3e9d43fba11fb37bd8ba590c76203e585505d Mon Sep 17 00:00:00 2001 From: Anjali Walsatwar Date: Wed, 18 Apr 2018 07:58:22 +0530 Subject: validation for file type selection Issue-ID: VNFSDK-243 Change-Id: Ib831eb9733a51408c73363702dd7032502f24710 Signed-off-by: Anjali Walsatwar --- .../common/directives/fileupload/fileuploadDirective.js | 10 +++++++++- .../src/main/webapp/vnfmarket/common/locale/locale-en.json | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/vnfmarket/src/main/webapp/vnfmarket/common/directives/fileupload/fileuploadDirective.js b/vnfmarket/src/main/webapp/vnfmarket/common/directives/fileupload/fileuploadDirective.js index 3f64841d..43137a5a 100644 --- a/vnfmarket/src/main/webapp/vnfmarket/common/directives/fileupload/fileuploadDirective.js +++ b/vnfmarket/src/main/webapp/vnfmarket/common/directives/fileupload/fileuploadDirective.js @@ -43,7 +43,15 @@ function link(scope, element, attrs) { element.bind("change", function (changeEvent) { scope.$apply(function () { - scope.fileUpload = changeEvent.target.files[0]; + var fileType = changeEvent.target.accept; + var ext = "." + changeEvent.target.value.match(/\.(.+)$/)[1]; + scope.fileUpload = null; + if (typeof fileType == undefined || fileType == "") { + scope.fileUpload = changeEvent.target.files[0]; + } + else if ((Array.isArray(fileType) && fileType.indexOf(ext) > -1) || (fileType == ext)) { + scope.fileUpload = changeEvent.target.files[0]; + } }); }); } diff --git a/vnfmarket/src/main/webapp/vnfmarket/common/locale/locale-en.json b/vnfmarket/src/main/webapp/vnfmarket/common/locale/locale-en.json index d086b9ac..f82b567e 100644 --- a/vnfmarket/src/main/webapp/vnfmarket/common/locale/locale-en.json +++ b/vnfmarket/src/main/webapp/vnfmarket/common/locale/locale-en.json @@ -57,7 +57,7 @@ "fields": { "fileUpload": { "label": "Select File", - "noFileSelected": "No file selected" + "noFileSelected": "No file selected (Select .csar file)" }, "shortDescription": { "placeholder": "Short Description" -- cgit 1.2.3-korg