diff --git a/app/assets/javascripts/uploadcare/build/_widget.coffee b/app/assets/javascripts/uploadcare/build/_widget.coffee index c68e4e521..a3d078564 100644 --- a/app/assets/javascripts/uploadcare/build/_widget.coffee +++ b/app/assets/javascripts/uploadcare/build/_widget.coffee @@ -15,6 +15,7 @@ expose('globals', uploadcare.settings.common) expose('start') expose('initialize') +expose('reset') expose('fileFrom') expose('filesFrom') expose('FileGroup') diff --git a/app/assets/javascripts/uploadcare/widget/base-widget.coffee b/app/assets/javascripts/uploadcare/widget/base-widget.coffee index e0d6a97f1..fc82a9687 100644 --- a/app/assets/javascripts/uploadcare/widget/base-widget.coffee +++ b/app/assets/javascripts/uploadcare/widget/base-widget.coffee @@ -132,6 +132,11 @@ uploadcare.namespace 'widget', (ns) -> dialogApi = uploadcare.openDialog(@currentObject, tab, @settings) @__onDialogOpen.fire(dialogApi) return dialogApi.done(@__setObject) + + destroy: () -> + @template.content.remove(); + @element.data('uploadcareWidget', null).off('.uploadcare') + return api: -> if not @__api @@ -139,7 +144,8 @@ uploadcare.namespace 'widget', (ns) -> 'openDialog' 'reloadInfo' 'value' - 'validators' + 'validators', + 'destroy' ]) @__api.onChange = utils.publicCallbacks(@__onChange) @__api.onUploadComplete = utils.publicCallbacks(@__onUploadComplete) diff --git a/app/assets/javascripts/uploadcare/widget/live.coffee b/app/assets/javascripts/uploadcare/widget/live.coffee index 6ed2bf4f0..639a0ae8d 100644 --- a/app/assets/javascripts/uploadcare/widget/live.coffee +++ b/app/assets/javascripts/uploadcare/widget/live.coffee @@ -69,6 +69,12 @@ uploadcare.namespace '', (ns) -> setInterval(ns.initialize, 100) # should be after settings.common(s) call ns.initialize() + + ns.reset = (container = ':root') -> + $(selector).each () -> + widget = $(this).data(dataAttr) + if(widget) + widget.destroy() $ -> if not window["UPLOADCARE_MANUAL_START"] diff --git a/test/dummy/app/views/welcome/with_value.html.erb b/test/dummy/app/views/welcome/with_value.html.erb index d995818da..e2135d133 100644 --- a/test/dummy/app/views/welcome/with_value.html.erb +++ b/test/dummy/app/views/welcome/with_value.html.erb @@ -50,8 +50,12 @@
Group incorrect:
-
+