Jump to content

Lock field when populated?


cryostar
 Share

Recommended Posts

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;
});

 

  • Like 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...