Jump to content

How to extend field visibilty rule?


regesh
 Share

Recommended Posts

Any field has visibility option (showif) that works perfect with field in current template. But i need to compare with the field in parent page template. Is it possible?
The task is like that: I have multiselect field in parent page - it is "Page Refference" field.   And i need field in children page compare that there is some page selected in parent multiselect field for it to show in editor.

Link to comment
Share on other sites

Maybe something like this, but I'm not entirely sure it will work, place it on ready.php:

$wire->addHookBefore('Inputfield::render', function($event){
  // the field where the field to hide exists
  $page = $inputfield->hasPage;
  $inputfield = $event->object;
  if($inputfield->name != "field_to_hide_if_parent") return;

  if($page->id){
    // maybe check for children of specific type?
    if($page->parent->template == "specific_type_of_page"){
      // the condition on the parent page?
      if($page->parent->multiselect_field->name == "some-name"){
          $inputfield->collapsed = Inputfield::collapsedHidden;
      }
	}
  }
});
  • Thanks 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

×
×
  • Create New...