processwire-issues icon indicating copy to clipboard operation
processwire-issues copied to clipboard

Overriding repeater adds new items instead of replacing

Open hiboudev opened this issue 1 year ago • 2 comments

Short description of the issue

I'm cloning a page content to another existing page. One of the fields is a repeater, if I override the repeater with a clone from the source page, items are added to the existing ones. If I remove all items before, the issue persists. I have to remove items, save the page, set the new repeater and save again. This is the working code:

$ofFromPage = $fromPage->of(false);
$ofToPage = $toPage->of(false);

$toPage->carChoicePerRound->removeAll();
// We have to save the page before to add items to the repeater, or we accumulate repeater items.
$toPage->save();
$toPage->carChoicePerRound = clone $fromPage->carChoicePerRound;
$toPage->save();

EDIT: just remembered I already posted a report that could be the same issue: https://github.com/processwire/processwire-issues/issues/1860

Expected behavior

Overriding repeater should replace the current one.

Setup/Environment

  • ProcessWire version: 3.0.240

hiboudev avatar Aug 10 '24 12:08 hiboudev

@hiboudev To clone a page you would have to use the $pages->clone() method.

ryancramerdesign avatar Aug 16 '24 13:08 ryancramerdesign

@ryancramerdesign I'm cloning only some fields to an existing page.

hiboudev avatar Sep 02 '24 15:09 hiboudev