2

I'm using the Entry Widgets Add-on and as part of that I'm trying to create a new widget for it which contains a File FieldType. So I'm using the File Field Class which comes with EE to accomplish that, and it's outputting all the right html markup, but what it's not doing is adding the Javascript click event to the Add File link.

As I understand it so far, this is not happening because each widget is loaded into the page using AJAX and so is loaded after all of the File Browser javascript is executed on DOM Ready.

I guess what I'm after is a straightforward way to either rerun the javascript so the events get added to my newly injected fields, or just recreate the click event itself. Or alternatively, if anyone know of a standalone way of getting the standard CP File browser working in my widget.

2

After much research it would seem the way to do it in my case is to manually call the add_trigger method on the ee_filebrowser JQuery object which exists in page.

So basically, I just added the following to my Widget template. When the Widget is loaded this JQuery is immediately executed.

<script type="text/javascript">
    $.ee_filebrowser.add_trigger(".choose_file", function (file) {

       // This is basically a callback method which is called after
       // you select a file in the File Manager modal window. The parameter
       // 'file' is an object representing the file you selected, which
       // has various properties pre-populated such as file_id, file_name etc.

       console.log(file); //Use Firebug in Firefox or similar to see all values.

       // Here you can then manually populate the hidden fields provided
       // by the File Field Class. 
    });
</script>
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.