Support Forum
Support › Meta Box Group › How to exclude elements from cloning in a group?Resolved
Hi,
Hopefully, someone can help with this.
I have a clone group that I dynamically fill with additional div's and image elements that I don't want to clone as they are cloning with the images already added. I can't add the elements outside of the group, since then the images won't be under the correct cloned group. So, is there any way to mark elements to not clone? Or is there an action/filter that gets called before a cloned group is displayed?
Thanks,
Ger
Hi Gerard,
It's not possible to exclude a subfield from a cloning group. But you can set the subfield to not clone the default value, please refer to this documentation https://docs.metabox.io/extensions/meta-box-group/#clone-default-values
Or find a filter here https://docs.metabox.io/category/filters/
Hi Nguyen,
Thanks for help.
What I'm doing is in the clone group, I have a geo lookup that returns the looked up location's google images and displays them. The user can then select an image to save as the main image for that location.
They can add multiple locations and images.
The way I insert the images from google is to insert a div and set them image as it's background. I also insert image elements for each of the other images returned from google places for that location. So, since this is all added by js, the default value doesn't have an effect. Each time I click add new clone, the images from the previous clone are duplicated.
I had a look at the filters, but I am unsure which would work in this situation. Do any of these filters get called when a group is cloned?
Thanks,
Ger
Hi Nguyen,
I was able to work around this. I used the listener I had added for the clone button click event to search for the duplicate div and remove it. I had to add a delay, so the cloned elements get created, so there is a slight flicker of the images before they are removed.
As an added feature for clone groups, could you look into a way to exclude elements with a specific class for example?
Thanks,
Ger
Hi,
I'm going to inform the developer team to consider adding a setting to exclude a subfield from the clone group to the to-do list for the future development of the plugin. Thanks.