Jump to content

Bug and possible cause: Page {ID} is not valid for {FIELD}


Lance O.
 Share

Recommended Posts

This is in response to the following posts:

https://processwire.com/talk/topic/5083-possible-bug-page-fieldtype-with-custom-selector-to-find-selectable-pages-returns-error-while-saving-page/

https://processwire.com/talk/topic/5683-inputfield-page-with-selector-rolesrole-page-1022-is-not-valid-for-field/

I am currently working on a site where I am using a Page field to assign multiple "products" to an individual "part". The "products" Page field stopped working recently and instead produces a "Page {ID} is not valid for {FIELD}" error. (Unfortunately, I'm not sure when it stopped working, but a design partner reported it to me today.)

I created a second Page field that used the exact same settings. The second Page field worked with no problems. When I exported both fields to compare them, I noticed that the original Page field had a parent_id of 1052 assigned to it. When I manually changed that parent_id to 0 to match the working Page field via phpMyAdmin, the original Page field started working correctly again.

Below are two exported fields. The first ("products") is the Page field that was giving me errors. The second ("products_test") is the test field I created that worked with no problems.

I looked in my database and did not find any record of 1052, so I can only assume that it must have been a page that was deleted at some point. If it was deleted, then perhaps that id value wasn't removed from the Page field at that time?

{
    "products": {
        "id": 147,
        "type": "FieldtypePage",
        "flags": 0,
        "name": "products",
        "label": "Products",
        "derefAsPage": 0,
        "parent_id": 1052,
        "labelFieldName": "title",
        "inputfield": "InputfieldAsmSelect",
        "findPagesCode": "return $pages->find(\"template=product,sort=title\");",
        "allowUnpub": "",
        "collapsed": 0,
        "showIf": "",
        "columnWidth": 100,
        "required": "",
        "requiredIf": "",
        "template_id": "",
        "findPagesSelector": "",
        "defaultValue": "",
        "addable": ""
    },

    "products_test": {
        "id": 172,
        "type": "FieldtypePage",
        "flags": 0,
        "name": "products_test",
        "label": "Products (TEST)",
        "derefAsPage": 0,
        "parent_id": 0,
        "findPagesCode": "return $pages->find(\"template=product,sort=title\");",
        "labelFieldName": "title",
        "inputfield": "InputfieldAsmSelect",
        "allowUnpub": "",
        "collapsed": 0,
        "showIf": "",
        "columnWidth": 100,
        "required": "",
        "requiredIf": "",
        "template_id": "",
        "findPagesSelector": "",
        "defaultValue": "",
        "addable": ""
    }
}
Link to comment
Share on other sites

For me this is throwing a more detailed error. But this still should not happen, as the php selection should override all the other selectionmodes.

"Session: Error saving field "page" - Page 1045 is not valid for page (Page 1045 does not have required parent 1044)"

P.S. I'm ultimately for not changing anything on field settings, because they are after all set up in any way for a reason.

Edit: Found the culprit in InputfieldPage.module

		if($field->findPagesCode) {
			// TODO: we don't currently validate these
		} 

		if($field->parent_id && $field->parent_id != $page->parent_id) {
			//Checks parent even though it shouldn't
		}

I'll open an issue over at GitHub.

Link to comment
Share on other sites

By chance, this same error just occurred on another site I am developing. Again, manually setting parent_id to 0 in the database fixed the problem.

Glad to see that you found the culprit. Looking forward to seeing a fix in the next release.  ;)

Link to comment
Share on other sites

  • 2 years later...

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