Modify the state of a repeater when an item is added
In v2 I had set up a listener to listen on the repeater::createItem event, but I can see that the repeaters are no longer using events in v3.
I tried adding something like
to the repeater and the listen on this event instead, but that doesn't seem to work.
I'm guessing I can override the action, doing exactly the same as what is done in the Repeater class, and tacking my code on at the end. I'd like to avoid this thought, as that just seems wrong and if there is a change the repeater action I'll have to update this as well.
Can someone point me in the direction of how this could be achieved.
10 Replies
What is the modification you're trying to do when an item is added?
I want to set the values in the new item, based off what the values are in the previous item.
I.e. if the order field in the previous item was 3 the new item should have the order field prefilled with 4.
Can you share your repeater code?
I had something like this in v2
And in v3 I tried adding
To the repeater and changing the event listener to listen for this instead. Which might be incorrect use of it, I couldn't completely wrap my mind around how it worked.
Wouldn't this work?
It might look like this:
I have this exact same logic applied for Delete action and it works just fine
Maybe something like this?
Doesn't seem to work either.
Where are you at in your experimentation? What is the code you're trying on v3?
@.modestasv I'm really sorry, I missed your answer before. I only saw it when I went through the whole thread once again 🤦♂️
Your answer actually works. This is what I made work.
I added
after()
that @pboivin suggested to the Repeater, which is stupid of me cus that's a validation rule.
Thank you both very much the help.No worries haha 😄