processwire / processwire-issues

ProcessWire issue reports.
44 stars 2 forks source link

Overriding repeater adds new items instead of replacing #1959

Open hiboudev opened 1 month ago

hiboudev commented 1 month ago

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

ryancramerdesign commented 1 month ago

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

hiboudev commented 1 month ago

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