Kiwi Chris Posted November 19, 2019 Share Posted November 19, 2019 I have a hook inside ready.php and I'm trying to get one page reference field pageBatch inside the repeater to update based on the value of another page reference field also inside the repeater, but so far haven't been able to get it to work. Is this possible, or is it a limitation of repeaters? Ideally I'd prefer to use a repeater than pagetable, as there will normally only ever be two or three items in the repeater, and the data entry with repeaters is a bit more intuitive for users as they don't have to remember to publish, and the entry is inline, rather than pop-up modals. $wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) { // pageBatch is a page reference field in a repeater if ($event->object->hasField == 'pageBatch') { $page = $event->arguments('page'); //returns the page that the repeater field is in, not the current repeater item $repeater = $page->repeaterField; //Want to be able to get the value of $repeater->pageField (a page reference field in the repeater) //Can refer to a page reference field in the page the repeater is in ok though eg $page->pageField works //but not a page reference field inside the repeater $repeater->pageField } }); Link to comment Share on other sites More sharing options...
dragan Posted November 19, 2019 Share Posted November 19, 2019 Maybe you need to add a getForPage() in there? https://processwire.com/talk/topic/18880-getting-one-repeater-items-as-content-for-other-repeater-item-on-the-same-page/ Try to use Tracy Debugger and see what dumps you get.https://adrianbj.github.io/TracyDebugger/#/debug-methods?id=bardump Link to comment Share on other sites More sharing options...
Kiwi Chris Posted November 28, 2019 Author Share Posted November 28, 2019 getForPage() doesn't help. if ($event->object->hasField == 'pageBatch') { bd($event->arguments(0), "Trigger Object"); $page = $event->arguments('page'); if ($page instanceof RepeaterPage) { $page = $page->getForPage(); bd($page->dispatchItems, "DispatchItems"); } Here is the segment of of code. the first bd() indicates that $event->arguments(0) is returning the page the repeater field is used on, NOT the page of the current repeater item, even though pageBatch is a field within the repeater. bd() doesn't even get called at the second instance, so even though the field pageBatch is contained within the RepeaterPage, I can't work out how to refer to any of the fields within the repeater. Link to comment Share on other sites More sharing options...
Robin S Posted November 28, 2019 Share Posted November 28, 2019 @Kiwi Chris, I think you want to make use of Inputfield::hasPage in this case. $wire->addHookAfter('InputfieldPage::getSelectablePages', function(HookEvent $event) { /* @var InputfieldPage $inputfield */ $inputfield = $event->object; $field = $inputfield->hasField; $edited_page = $event->arguments('page'); $page_containing_inputfield = $inputfield->hasPage; // a Repeater page in your case if($field->name === 'pageBatch') { // Use $page_containing_inputfield as needed here // ... } }); 1 Link to comment Share on other sites More sharing options...
Kiwi Chris Posted November 28, 2019 Author Share Posted November 28, 2019 @Robin SThanks that's what I was looking for. hasPage returns the repeater page. I think I now have the capability to deal with most scenarios for page fields where they have dependencies. I think they still rely on the page being saved, but that's OK for now, although it would be great if I could get them updating via ajax. Inside my hook I now have something like this: if ($event->object->hasField == 'pageBatch') { $inputfield = $event->object; $repeater = $inputfield->hasPage; //Now possible to refer to repeater fields in hook. } Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now