Jump to content
cb2004

Remove a fieldset tab from specific pages of a template

Recommended Posts

I have a repeater, which with the use of a hook I can stop that from displaying from certain pages:

<?php

$wire->addHookAfter("ProcessPageEdit::buildForm", function(HookEvent $event) {
	$process = $event->object;
	$form = $event->return;
	$page = $process->getPage();

	if ($page->template->id == 44 && $page->parent->id != 1020 && $page->parent->id != 1021) {
		$form->remove($form->getChildByName("repeater_partners"));
	}
});

My repeater is in a fieldset tab, so on any pages where the repeater should not be displayed, the fieldset tab is (the repeater is not). Any way to remove this within the above?

Cheers.

Share this post


Link to post
Share on other sites

Tabs are cached while building the form, so you're renoving the inputfield, but not the tab for it. There's a function to remove the tab as well in ProcessPageEdit. I'm on mobile, so please look for it on your own.

Share this post


Link to post
Share on other sites

Should anybody need this:

$pages->addHookAfter("ProcessPageEdit::buildForm", function(HookEvent $event) {
	$page = $event->object->getPage();
        $form = $event->return;

	if ($page->template->id == 44 && $page->parent->id != 1020) {
		$fieldset = $form->find("id=Inputfield_fieldset_tab_2")->first();
		$form->remove($fieldset);
		$event->object->removeTab("Inputfield_fieldset_tab_2");
	}
});

Just replace the $page->template->id with the id of your template, and the $page->parent->id to what you want (or something similar). Finally replace fieldset_tab_2 with the name of your field.

  • Like 5

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...