Jump to content

Page cannot have itself selected in a page field, causes save error


K Phoenix
 Share

Recommended Posts

Sorry if that topic title is confusing. I'm really not sure how else I can describe the issue that succinctly!

Let me clarify with an example:

Say I have three pages: Type 1, Type 2, and Type 3. All pages are using the same template, type-template.

I also have three Page fields: Field A, Field B and Field C. All are dereferenced as multiple page/PageArray, and all are set to choose pages with the above type-template, using checkboxes if that matters. This means that my page choices for Field A are Type 1, Type 2 and Type 3, and the exact same for Fields B and C. (Effectively, these three fields are identical; they're direct copies of one another, in fact.) These fields are currently attached to type-template and no other templates.

Now say that I'm editing Type 1's page, Field A. If I select either or both of Type 2 or Type 3 in Field A, I can save the page and everything works just fine and dandy. But if I select Type 1 as an option in Field A, I get the "Error saving field "field_a" - Page #### is not valid for field_a" error (where #### is the id of Type 1). The same thing happens if I select Type 1 as an option in Fields B or C. No matter which field I'm editing, I cannot select Type 1 as an option while I am editing Type 1...

...but I can select Type 1 and save just fine if I'm editing Type 2's page. Instead, Type 2 becomes "invalid" while I'm editing the Type 2 page. Likewise, Type 3 is "invalid" only while I'm editing Type 3, and perfectly acceptable on the other two Types. I'm not sure whether needing to select the current page as an option is unusual, but Field A et al. define relationships between the three Types, and I often need to say something like "dogs don't like squirrels or cats (Field A), but dogs do like people and other dogs (Field B)". Right now that "dogs like dogs" is impossible to achieve thanks to the error.

I've tried changing the input field type from checkboxes to anything else that lets me choose multiple pages. I've tried all four methods of selectable pages, but I get the error whether I'm selecting using the parent, the template, a custom selector or custom PHP.

I would just shrug and assume that maybe this isn't currently possible, but the really baffling part is that it should be, far as I can tell. This project is very, very similar to an earlier test project, and the other project does not have this issue. If I'm on the "dogs" page there, I can select "dogs" as an option for a field with no problem. I've been back and forth and back and forth comparing the settings of the two fields and the two templates, and I can't see a meaningful difference. Both projects are using the same version of PW (2.5.3), although the functioning one has been steadily upgraded from something like 2.4.10 and this new one was installed as 2.5.3. The only other thing I can think of right now is that the environments are different: the working one is on a remote server and PHP 5.5.7, while the broken one is on a local environment with PHP 5.4.36. I don't know; would that affect this? :/

I've done some searching around and so far have turned up a few threads on similar errors, like https://processwire.com/talk/topic/8400-possible-page-field-bug/ and https://processwire.com/talk/topic/7387-pageautocomplete-page-x-is-not-valid-for-y/ . I've tried to read through them and the threads linked within (keyword: "tried"; it's unreasonably late/early here right now and I'm about to hit the hay after posting this, so maybe another read after I've rested will reveal something!), but most of those seem to have to do with using page ids in custom selectors instead of the page names. I've tried both ids and names and still have this problem, and I've tried just using the parent/template options with similar luck.

While I can move on with other parts of development (and fill in the rest of those fields) for now, this is definitely important for the site I'm building and I'll need to figure something out eventually. Any insight you knowledgable folk can give me—any fixes, any PHP settings that might somehow be the culprit, anything painfully obvious I might've missed at this unfortunate hour—is much appreciated! And let me know if you need me to provide any more information. :) Thanks!

Link to comment
Share on other sites

On a bit of a hurry right now, so just hopping in to mention keyword "circular reference". This has been discussed every now and then, and current situation (unless I've missed something) is that it's (intentionally) prevented for Page fields. There have apparently been some changes regarding circular reference checks recently, so it might've been possible at some point, though it was never really intended  :)

Anyway, I'm not saying that this shouldn't possible, just trying to provide hopefully some insight about why this might happen.

If you need a quick way to get past this, one option would be removing current page from selectable options and including a single checkbox, something along the lines of "this page itself". Or something like that :)

  • Like 2
Link to comment
Share on other sites

A possible solution could be to use an other page to select but you show the current Page title. Here's how to do:

In the Page field settings use Custom PHP code to find selectable pages

type:

$p = $page->parent;
$p->title = $page->title;

$PageArray = $pages->find("template=type-template, id!=$page->id");
$PageArray->add($p);
$PageArray->sort('title');

return $PageArray;

Then when the field contains the $page->parent, you know that they wanted to select the current page.

  • Like 4
Link to comment
Share on other sites

Thank you both for your replies! Either of those should work, I think, although I ended up going with Martijn's solution for now since it saves me a few fields. (Wish I could mark both as solved, since teppo's contains the explanation for why it doesn't work as-is!) Unfortunately it's going to make some later parts of my templates a hair more complicated than they were going to be, but nothing unmanageable. I guess that's just what happens when large parts of your code rely on something that doesn't actually work, haha.

The circular reference issue makes sense now that you mention it, although it's still kind of odd that I got it working earlier—I had that test project set up and "functioning" well before adrian made that report in September, and it still works now even after a few updates. Maybe it's because it behaved differently in an earlier version, and for whatever reason a later update didn't "break it" the way it should have? Ah, well, quirks happen.

Thanks again for the quick assistance!

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