• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

File Upload in repeat group

nine007

Member
Good Day

I have a group with a few elements and a file upload element set to repeat.

The file upload element does not want to open the dialog to add files when I press the add button, it only does so on the first, but not when I want to add more data.

Any help

thank you
 
Good Day

The file upload with ajax is still not working in repeat group, any idea when it will be fix, really need it to work.

thank you
 
Dears, bumping this one please, is it possibly too difficult? If so, please let us know. Thanks.
 
I am too invested in fabrik and in a current project in which I'd worked over 2 months having this working was essential. So I hacked the following together which seems to be working quite decently. Please share if you find any issues.

Make sure to add the following code somewhere on client side, right before form is submitted:

Code:
normalizeAttachmentsWithinRepeatableGroups:function() {
                var containers = document.getElements('.fabrikSubGroup .plupload_container'), toNormalize = {}, key, keys = [];
              
                for (var i = 0, n = containers.length; i < n; i++) {
                        key = containers[i].getParent('.fabrikSubGroupElements').getElement('.plg-internalid input').get('name');
                        key = key.split('[')[0];
                        if (typeof toNormalize[key] == 'undefined') {
                                toNormalize[key] = [];
                                keys.push(key);
                        }
                        toNormalize[key].push(containers[i]);
                }
              
                var els, name, j, k, ji, ki;
              
                for (var i = 0, n = keys.length; i < n; i++) {
                        for (j = 0, k = toNormalize[keys[i]].length; j < k; j++) {
                                els = toNormalize[keys[i]][j].getParent('.fabrikSubElementContainer').getElements('input[type=hidden]');
                                for (ji = 0, ki = els.length; ji < ki; ji++) {
                                        name = els[ji].get('name').replace('[]', '['+j+']');
                                        els[ji].set('name', name);
                                }
                        }
                }
        }

In your form plugin onAfterProcess event or in a PHP plugin onAfterProcess execute the following PHP code (naturally there're some assumptions below about what your attachment element is called, in this case its simply attachment):

Code:
        public function onAfterProcess() {
                $model = $this->getModel();
                $els = array();
                $tbls = array();
                $parents = array();
              
                foreach ($model->groups as $group) {
                        if ($group->canRepeat()) {
                                foreach ($group->elements as $element) {
                                        if ($element instanceof PlgFabrik_ElementFileupload) {
                                                $join = $group->getJoinModel()->getJoin()->table_join;
                                                $name = $join.'___'.$element->getElement()->name;
                                                $els[] = $name;
                                                $name = $join.'_repeat_'.$element->getElement()->name;
                                                $tbls[] = $name;
                                                $name = $join.'___id';
                                                $parents[] = $name;
                                        }
                                }
                        }
                }
              
                $db = JFactory::getDbo();
                $query = $db->getQuery(true);

                foreach ($parents as $i => $parent) {
                        if (!isset($_POST[$parent]) || !is_array($_POST[$parent])) {
                                continue;
                        }
                      
                        foreach ($_POST[$parent] as $repeatCounter => $parentId) {
                                $tbl = $tbls[$i];
                                $query->clear()->delete($tbl)->where('parent_id = '.$parentId);
                                $db->setQuery($query)->execute();
                              
                                if (!isset($_POST[$els[$i]]) || !isset($_POST[$els[$i]][$repeatCounter]) || !is_array($_POST[$els[$i]][$repeatCounter])) continue;
                              
                                $repeatInstance = $_POST[$els[$i]][$repeatCounter];
                              
                                if (empty($repeatInstance) || !is_array($repeatInstance)) continue;
                              
                                $repeatInstance = $repeatInstance['id'];
                              
                                if (empty($repeatInstance) || !is_array($repeatInstance)) continue;
                              
                                $files = array();
                              
                                foreach ($repeatInstance as $file => $val) {
                                        $files[] = $parentId.','.$db->quote($file);
                                }
                              
                                if (empty($files)) continue;
                              
                                $query->clear();
                              
                                $query->
                                        insert($tbl)->
                                        columns(array('parent_id', 'attachment'))->
                                        values($files)
                                        ;
                              
                                $db->setQuery($query)->execute();
                        }
                }
        }
 
Last edited:
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top