Jump to content

[SOLVED] Required only if with required field action issue


PWaddict
 Share

Recommended Posts

On my template's "Required field action" is set to Unpublish the page. I have a Page Table field inside that template with the condition "Required only if". So when a checkbox is checked the Page Table field is required.

The problem is that if the checkbox is unchecked so the Page Table isn't required when I save the page it gets unpublished with the error: "Session: Page unpublished because field "test_pagetable" is required" then I can publish the page again without issues then if I save the page again it gets unpublished with the above error and so on...

Link to comment
Share on other sites

@Juergen Can you please help me to fix this with a hook?

I'm trying to change the required attribute to 0 of my pagetable field right before the page is saved but it doesn't work: 

$wire->addHookBefore('Pages::saveReady', function(HookEvent $event) {

  $page = $event->arguments(0);
  $field = $page->mypagetable;

  if($page->template == 'mytemplate' && !$page->mycheckbox) {
    $field->required = 0;
  }

});

 

Link to comment
Share on other sites

On 30/04/2018 at 2:22 AM, PWaddict said:

I have a Page Table field inside that template with the condition "Required only if". So when a checkbox is checked the Page Table field is required.

What rule did you enter in the "Required only if" input? I tested it with a checkbox field and couldn't reproduce the issue.

2018-05-01_152407.png.19cf3bf899a6802d9986b20fcf5465f9.png

Link to comment
Share on other sites

10 minutes ago, Robin S said:

What rule did you enter in the "Required only if" input? I tested it with a checkbox field and couldn't reproduce the issue.

2018-05-01_152407.png.19cf3bf899a6802d9986b20fcf5465f9.png

Yes the rule is: mycheckbox=1

Have you selected the "Unpublish the page" on Required field action under Advanced on the template?

You save the page over and over with UNCHECKED checkbox and the page doesn't unpublished???

Link to comment
Share on other sites

  • PWaddict changed the title to [SOLVED] Required only if with required field action issue

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...