Search the Community
Showing results for tags 'wrong vlues'.
-
Hello, To compare repeater items when someone added or removed items to/from the repeater, I use this hook wire()->addHookAfter('Pages::saveReady', function($event) { $page = $event->arguments[0]; if($page->isChanged('repeater')) { //get page before changes : https://processwire.com/talk/topic/9734-determine-old-vs-new-value-of-field-when-saving/?do=findComment&comment=106166 $oldPage = $this->wire('pages')->getById($page->id, array( 'cache' => false, // don't let it write to cache 'getFromCache' => false, // don't let it read from cache 'getOne' => true, // return a Page instead of a PageArray )); bardump("new count: {$page->repeater->count}"); bardump("old count: {$oldPage->repeater->count}"); } }); When I add a repeater item, both counts are identical. But they shouldn't. When I remove a repeater item, the counts come out correct. I verified this behavior on a blank PW 3.0.62 install. So I think it is a bug. Can someone please check if they find the same behavior? Thank you. I also tried it with this hook wire()->addHookAfter('Page(template=basic-page)::changed(repeater)', function($event) { // old value bardump($event->arguments[1]->count); // new value bardump($event->arguments[2]->count); }); Same outcome. For the second hook to fire, you need to adjust line 1005 in wire/core/Wire.php to read if(($hooks && $hooks->isHooked('changed()')) || !$hooks) { because of this bug.
- 2 replies
-
- wrong vlues
- page changed
-
(and 1 more)
Tagged with: