Jump to content

Can I toggle a repeater item on/off with API?


JayGee
 Share

Recommended Posts

Pretty much as per the topic subject - trying to figure out how to toggle a repeater on/off using the API. Have tried setting the page status which indeed seems to hide the item but this doesn't reflect the toggle on the page editor so when you next save the page they come back on.

Link to comment
Share on other sites

On 10/21/2019 at 4:51 PM, adrian said:

By toggle off, I assume you mean "unpublish"? It's possible, but it's a real mess. However if you read through this: https://github.com/processwire/processwire-issues/issues/36 you'll be able to get it working.

Thanks all - that does all seem a bit of a headache - it's not mission critical so will probably just stick with deleting unused items rather than disabling them or just let the user manually manage them. Had naively assumed that as repeater items were pages behind the scenes that the 'toggle' would just be a proxy for unpublishing them or something similar.

Link to comment
Share on other sites

6 minutes ago, Guy Incognito said:

Thanks all - that does all seem a bit of a headache - it's not mission critical so will probably just stick with deleting unused items rather than disabling them or just let the user manually manage them. Had naively assumed that as repeater items were pages behind the scenes that the 'toggle' would just be a proxy for unpublishing them or something similar.

They are just pages behind the scenes and unpublishing would work if Ryan would fix the 2048 vs 2049 issue, although I guess at this point it might be a breaking change.

Did you try:

$item->addStatus(Page::statusUnpublished);
$item->removeStatus(Page::statusOn);

 

Link to comment
Share on other sites

5 minutes ago, adrian said:

Did you try:


$item->addStatus(Page::statusUnpublished);
$item->removeStatus(Page::statusOn);

 

I think I did - but will double check as got frustrated and parked it for later on lol!

I think it was causing strange things like the item still showing in the repeater without affecting the on/off toggle and then re-enabling when the parent page was saved. Will give it another go and report back.

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