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

getChanges(true) with repeater: trigger changes for 2 consecutive save()

Open hiboudev opened this issue 2 years ago • 2 comments

  1. Repeater is empty, I add an item, save page, getChanges(true) contains something.
  2. Issue: I save page again without changes and getChanges(true) contains again the same as previous.
  3. The third save: getChanges(true) is empty.

No issue when deleting an item, just when adding one.

Test code:

$this->addHookBefore('Pages::saveReady', function (HookEvent $event): void {
    $page = $event->arguments(0);
    $changes = $page->getChanges(true);

    if (!array_key_exists('myRepeater', $changes)) return;

    wire()->notices->message("CHANGE".print_r($changes, true));
});

Output

CHANGEArray ( [myRepeater] => Array ( [0] => [1] => ) )

  • ProcessWire version: 3.0.228

hiboudev avatar Nov 21 '23 16:11 hiboudev

Same issue with Repeater Matrix when adding an item.

hiboudev avatar Nov 22 '23 14:11 hiboudev

Maybe this could help ? https://processwire.com/talk/topic/16407-wrong-before-and-after-values-for-repeaters-on-page-ischanged/

romaincazier avatar Dec 21 '23 08:12 romaincazier