Take the 2-minute tour ×
ExpressionEngine® Answers is a question and answer site for administrators, end users, developers and designers for ExpressionEngine® CMS. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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>
share|improve this answer
    
Nice work on this. –  Justin Kimbrell Aug 14 '13 at 16:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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