cryostar Posted June 27, 2021 Share Posted June 27, 2021 Is it possible to lock a field on the Edit page once it's been populated? If not, how do I prevent users from editing a field further? Link to comment Share on other sites More sharing options...
BillH Posted June 27, 2021 Share Posted June 27, 2021 You could use a hook as in this discussion: Putting the hook in ready.php may well be a good plan. Link to comment Share on other sites More sharing options...
cryostar Posted June 29, 2021 Author Share Posted June 29, 2021 Thanks @BillH! Using hooks is actually on top of my head though I was just wondering if there are other straightforward solutions that don't require code. If anyone has a requirement like I do that should make certain fields read-only when they are populated, here's how I did it (saved under ready.php): $wire->addHookBefore('Page::loaded', function(HookEvent $event){ $_page = $event->object; if($this->page->process !== 'ProcessPageEdit') return; //Run only if you're on the admin page editor if('specifictemplate' != $_page->template) return; //If only you want to lock it for certain fields if(!$_page->thatfield) return; //This is a Page Reference that returns false if there is no value $thatfield = $_page->getField('thatfield'); $thatfield->collapsed = Inputfield::collapsedNoLocked; }); 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