Monday, July 13, 2015

Concrete5.7: Dynamically Add The File Selector

The documentation for the newly released Concrete5 version 5.7 may not be complete yet. I haven't found in the documentation a way to dynamically add the file selector wherever I want and how many times I want on a page, but I figured it out, so here it is:


1
2
3
        var selector = 'whatever-you-may-use-here';
        $("#some-container").append('<div class="ccm-file-selector" data-file-selector="' + selector + '"></div>');
        $('[data-file-selector=' + selector + ']').concreteFileSelector({'inputName': 'fID-' + selector, 'chooseText': 'Select an image', 'filters': [{"field":"type","type":1}] });

I hope that this was helpful :)
type:1 at the end is for images.
Other values for the file types can be found in the Type class from the Concrete\Core\File\Type namespace as follows:


1
2
3
4
5
6
7
8
    // File Type Constants
    const T_IMAGE = 1;          //!< @javascript-exported
    const T_VIDEO = 2;          //!< @javascript-exported
    const T_TEXT = 3;           //!< @javascript-exported
    const T_AUDIO = 4;          //!< @javascript-exported
    const T_DOCUMENT = 5;       //!< @javascript-exported
    const T_APPLICATION = 6;    //!< @javascript-exported
    const T_UNKNOWN = 99;       //!< @javascript-exported