Elementor 3.6+ ; how to listen for changes in Repeater control when Add, Duplicate and Delete Item events occur? #18707
Replies: 11 comments 3 replies
-
Hi @oooh-boi, First of all, the code above you is used in the Front End, not the editor, so that is not the way to go. Generally, you can only force a remote render on elements that don't have a JS template. elementor/includes/elements/container.php Lines 115 to 139 in 02fb2b7 The reason for this is that when Elementor sends a re-render command when any element is changed, it first looks for a JS template, and only fetches from the server if it doesn't find one. Since Flex Containers have a JS template (created in the However, you can listen to add/duplicate/remove actions of repeaters using our JS API hook system. You can see the repeater hooks here: You can add hook callbacks for If at this point what you want to do is run a hook callback that will call a server-side re-rendering, you could potentially achieve it through the following course of action: Disclaimer: I have never done something like the following, and I really DO NOT recommend doing this though because of any number of unknown and unintended side-effects such an action could cause. Once you get your relevant element's JS
|
Beta Was this translation helpful? Give feedback.
-
Thank you for taking the time to put this together Udi! I'm not a core developer and mostly understand things to a certain degree. With what you wrote about, how to do it practically? How do I add a JS hook for the repeater? Cheers! |
Beta Was this translation helpful? Give feedback.
-
I've come up with the following but not sure how to go on...
|
Beta Was this translation helpful? Give feedback.
-
This (#9063 (comment)) code should point you to the right direction. Despite what you said, it does work... similar code is used in Elementor Pro. But - Note that this code has to run in the Editor's The |
Beta Was this translation helpful? Give feedback.
-
I'm sorry but wouldn't it be simpler and easier for both of us if you provided an example code? Yes, my JS is enqueued via the Do I need another hook to run the code, like the 'panel:init' or so? I did the following but the code fails because
Could you please provide an example that might work? I'm sorry, I just don't have any other option but to beg for a bit of help. If you can't help, could you recommend anyone else? |
Beta Was this translation helpful? Give feedback.
-
@oooh-boi To do that, you create three files:
Replace
Note that if you create a single hook file, you still need to do a NAMED export from that single hook file, because the Component's
|
Beta Was this translation helpful? Give feedback.
-
OK, thanks a lot for your time! It doesn't look like we are on the same frequency. I'm talking from the point of view of an Elementor add-on and what you have provided as a general guideline here.
Where does the new code meet the previously suggested one this? Is there a way to monitor changes in the editor's history and perhaps avoid creating hooks? Do you have any other suggestions on how to simplify all of this? Thanks a lot! |
Beta Was this translation helpful? Give feedback.
-
Unfortunately, I'm ending up with "Uncaught SyntaxError: import declarations may only appear at top level of a module". I thought that adding the Apart from that, here's what the folder structure looks like :
The files you told me to add: |
Beta Was this translation helpful? Give feedback.
-
I don't think I know how, sorry. Maybe better to forget about all this. Thank you for all your help!!! |
Beta Was this translation helpful? Give feedback.
-
elementor.hooks.addAction('panel/open_editor/widget/{widget_name}', ( panel, model, view ) => { // Bind 'before:remote:render' event to trigger option updates before the view is rendered model.on('before:remote:render', onSettingChange); }); |
Beta Was this translation helpful? Give feedback.
-
I am up to create a new panel under the Advanced settings/tab in the Elementor editor. The extension includes REPEATER control plus some other ones.
The problem I have relates to the
onElementChange()
method which works fine for every other option but the REPEATER control.More precisely, my goal is to :
a) listen for an ADD, DUPLICATE and DELETE repeater items
b) re-render the target Widget or the Container in the editor preview upon any of these changes.
I believe that I have to add the listener to the REPEATER control manually but I have no clue how to do that.
(This post is something that doesn't work any longer)
So, the above code is a pretty-much basic structure and it would be awesome if someone is willing to let me know how things work with adding the listeners to Repeater and how to re-render the widget/container in the editor preview.
Thanks a lot!
Beta Was this translation helpful? Give feedback.
All reactions