Multiple type file fields in cloneable groups not cloning properly
- This topic has 7 replies, 2 voices, and was last updated 2 years, 3 months ago by
Peter.
-
AuthorPosts
-
November 21, 2022 at 5:06 AM #39241
Virgile Bedin
ParticipantHello,
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 !)November 21, 2022 at 10:27 PM #39249Peter
ModeratorHello 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.
November 22, 2022 at 12:08 AM #39253Virgile Bedin
ParticipantHello,
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.December 14, 2022 at 11:43 PM #39802Virgile Bedin
ParticipantHello, 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?December 15, 2022 at 10:53 PM #39826Peter
ModeratorHello,
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.
December 16, 2022 at 1:19 AM #39840Virgile Bedin
ParticipantHello,
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 .
January 11, 2023 at 10:03 PM #40201Virgile Bedin
Participantme 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 !
VirgilJanuary 14, 2023 at 10:23 AM #40227Peter
ModeratorHello,
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.
-
AuthorPosts
- You must be logged in to reply to this topic.