joe_g Posted 14 hours ago Share Posted 14 hours ago Hey there, So I'm trying to update a checkbox in the admin depending on a condition (if the current page exist in a PageArray elsewhere). I'm not sure how to navigate the hooks to achieve this. I suppose I'm trying to do "before render, check if this page exist in the PageArray, if yes, set checkbox to checked, otherwise leave unchecked". many thanks! Link to comment Share on other sites More sharing options...
Sanyaissues Posted 9 hours ago Share Posted 9 hours ago $wire->addHookBefore('Inputfield::render', function (HookEvent $event) { $inputfield = $event->object; // Proceed only for 'yourField' if ($inputfield->name !== 'yourField') { return; } // Get the associated page if (!($page = $inputfield->hasPage)) { return; } // Check if the page is part of the yourPageArrayField on page with id 1 // (or whatever the ID of the page with your pageArraField is) $productPages = pages()->get(1)->yourPageArrayField; if ($productPages->has($page)) { $inputfield->attr(['checked' => 'checked', 'value' => 1]); } }); 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