From 24d0ae03899f23d8fb30098b4f1524031d22cc67 Mon Sep 17 00:00:00 2001 From: Welling Guzman Date: Wed, 9 Nov 2016 19:41:17 -0400 Subject: [PATCH] clear the input after a forbiden file --- app/core/uis/single_file.js | 8 ++++++-- app/utils.js | 5 +++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/core/uis/single_file.js b/app/core/uis/single_file.js index 565e45ffea8e1..7e2289660d57e 100644 --- a/app/core/uis/single_file.js +++ b/app/core/uis/single_file.js @@ -21,12 +21,13 @@ define([ 'underscore', 'backbone', 'core/t', + 'utils', 'core/UIComponent', 'core/UIView', 'core/table/table.view', 'core/overlays/overlays' ], - function(app, _, Backbone, __t, UIComponent, UIView, TableView, Overlays) { + function(app, _, Backbone, __t, Utils, UIComponent, UIView, TableView, Overlays) { 'use strict'; @@ -181,7 +182,10 @@ define([ var target = $(event.target); var file = target[0].files[0]; var model = this.fileModel; - model.setFile(file, this.options.settings.get('allowed_filetypes')); + var allowed = model.setFile(file, this.options.settings.get('allowed_filetypes')); + if (allowed === false) { + Utils.clearElement(target); + } }, 'click button[data-action="computer"], .ui-thumbnail-dropzone, .single-image-thumbnail img': function(e) { this.$el.find('#fileAddInput').click(); diff --git a/app/utils.js b/app/utils.js index 7351a24e76bee..a59435cdefeff 100644 --- a/app/utils.js +++ b/app/utils.js @@ -125,5 +125,10 @@ define(function() { return value == null || value === ''; }; + Utils.clearElement = function(element) { + element.wrap('
').closest('form').get(0).reset(); + element.unwrap(); + }; + return Utils; });