cubiclesoft / jquery-fancyfileuploader

A jQuery plugin to convert the HTML file input type into a fancy file uploader under a MIT or LGPL license. Mobile-friendly too!
58 stars 27 forks source link

Feature request: access existing instance of fileupload #11

Closed bouskdav closed 4 years ago

bouskdav commented 4 years ago

Hi,

i would really apreciate possibility to modify options on-the-fly - currently i just recreate the FFU with new options.

(e.g. accept types)

Thanks, cheers, David

cubiclesoft commented 4 years ago

You might be able to use preinit to save a reference to the internal settings object for later. Then alter the settings.accept array as desired. For a simpler implementation, don't set an accept attribute on the input element.

Changing the underlying duplicate input element's accept attribute would require accessing $this.data('fancy-fileupload').form.find('input[type=file]').attr('accept', 'new value'). preinit is called in context of this, so it should be possible to save that context for later as well. This is a small hack to access semi-internal structures. It'll probably work fine though.

An alternative is to set up the number of instances you need of different types up front. I assume you have some sort of switching interface (radio buttons/dropdown). Then just show/hide a surrounding div to show the correct widget when the file type changes.

cubiclesoft commented 4 years ago

Updated the documentation to show how to access some of the internals. Added a reference to the settings object to the internals for easier access. Added postinit option for complete coverage.

bouskdav commented 4 years ago

Awesome man, thanks for that!