Support Forum
Support › Meta Box Group › Multiple type file fields in cloneable groups not cloning properly
Hello,
I have a little problem with groups, clones and file fields,
i would like to make a cloneable group with three type "file" fields in it, and when adding a clone, only the first file input gets correctly cloned and appears, the other ones miss their file input and seems to have been given the same uniquid() than the first one...
I looked into clone.js, file.js and group.js but no success, the only thing i could notice is that the 'clone' event for file fields is only triggered once.
i tried with the simplest example like below..
array(
'type' => 'group',
'id' => 'test_group',
'clone' => true,
'fields' => [
[
'id' => 'field1',
'type' => 'file',
],
[
'id' => 'field2',
'type' => 'file',
],
[
'id' => 'field3',
'type' => 'file',
],
]
)
thank you for your help !
(and thank you also for the amazing work you've done with your plugins so far !)
Hello Virgile,
Thank you for your feedback.
I see that issue, I've escalated this to the development team to fix it in the next update. Let me know if you have any questions.
Hello,
thank you for you answer,
if you could give me a quick fix, however complicated it is (not scared of js and php),
so i don't have to wait the next update it would be great. I really need this functionnality for a dev, and i could'nt fix it by myself.
Hello, me again to up this post..
i see there was an update on metabox Groupn but nothing about my issue, and i really need it.
could you please ask devs for a quick fix?
Hello,
This issue has been fixed in this commit https://github.com/wpmetabox/meta-box/commit/95127eb7233e31d992d1fdf78c0cca9eb3685147
You can apply the changes to your site while waiting for a new update. Thanks.
Hello,
I'm sorry to have to tell you that it doesn't exactly fix the problem, the fields get cloned, but not properly, as they are all given the same temporary name.
by the way i could use your code to find a way to fix it, and this seems to do it,
between lines 109 and 118 of js/file.js
//$clone.find( '.rwmb-file-input' ).attr( 'name', inputName + '[]' ).not( ':first' ).remove();
$clone.find( '.rwmb-file-new' ).each( function() {
inputName = '_file_' + rwmb.uniqid(); // need to generate a temp unique name for each new input file
$( this ).find( '.rwmb-file-input' ).attr( 'name', inputName + '[]' ).not( ':first' ).remove();
$key = $( this ).siblings( '.rwmb-file-index' ); // find the nearest index_field
$key.val( inputName ); // assign the new temporary name to the file_index field
} );
//$key.val( inputName );
but i guess that there is a little bit more refactor and cleaning to do in this function as there is still pieces of code that are maybe useless..
can you at least ask the devs if what i did is ok and doesn't risk to break anything else ?
as a result, i seem to be able to upload multiple files even when cloning multiple times befors sending the form. looks like it's working .
me again, to give a la up and hope to my previous message, to inform you that the fix you've pushed in the last update did not really fix the problem, see my last message..
it makes the field duplicate but they keep the same temporary name, so they are not usable for upload.. as only one file gets uploaded.
i pasted my fix on my last message, again : not sure it's optimal but looks like it works, and i would be glad to know what devs thinks about it, if it's not breaking anyhting elsewhere, then i'll continue using it. untille you really fix it 🙂
have a nice day !
Virgil
Hello,
Thanks for your feedback.
I've informed the development team to check this and continue to fix the issue. I will inform you when it's done.