Jump to content

How to assign Users to Page Field


clsource
 Share

Recommended Posts

Hello, 

I'm trying to create a template that have a field for storing what user modified it.

So when editing a page I could have a Single Selection for users.

I used a page field with a parent of Users.

but when I try to save it says

" Page 3234 is not valid for owner"

Thanks for any help.

:P

Link to comment
Share on other sites

I just set up a page field with parent of Admin > Access > Users and it works fine. Do you get that error when saving the field in the admin, or a page with that field on it, or saving the page via the API?

I saved from admin (superuser), and using the APi.

but @renobird solution was what i needed.

:P

Link to comment
Share on other sites

If you need to sort by some other field (Say you have first_name and last_name fields assigned to your user template)

Use the "Custom selector to find selectable pages" option.

template=user, sort=last_name

And roles=<role name> ex: roles=admin if you need to only show certain users in a given role :P.

Yep ProcessWire is that Awesome.

And the people in the forums are the best :P

  • Like 4
Link to comment
Share on other sites

  • 2 months later...

I just set up a page field with parent of Admin > Access > Users and it works fine. Do you get that error when saving the field in the admin, or a page with that field on it, or saving the page via the API?

I set up a page field with parent of Admin -> Access -> Users but it doesn't work... Field saved successfully, but no match with page autocomplete module.

Any idea why?

Update

Seems to be a PageAutocomplete bug. Works with PageListSelectMultiple.

Any chance to get it Work with PageAutocomplete?

Link to comment
Share on other sites

Thanks Soma!!!

Get it work with your screenshots, but one additional change needed...

I have to add "name" to "Field to query for autocomplete", but also remove title!

Found it at your third screenshot.

"title name" doesn't work, but only "name" does it! :)

Link to comment
Share on other sites

  • 1 month later...

I saved from admin (superuser), and using the APi.

but @renobird solution was what i needed.

:P

Hi all.

In the end, the question wasn't really answered and I'm running into the same problem. 

Template "space" needs a space_owner field who's a registered user. When I do 1-2-3 below, one can't save a new "space" page because of same error, namely that the user page selected from the Page field is not accepted at page save time. 

(1)

Define a "space_owner" field to select a single user page, with a selector like this:  'template=user, roles=space-owner, check_access=0' .

The field saves properly.

I don't have a problem w/ the dropdown, I've defined a pretty_name Text field which I added to the user template and use it as the label field.

(2) 

Add this space_owner field to the "space" template. no problem

(3) 

Create a new space page.

The select (dropdown) shows the correct list of users based on the selector.  

Pick the user page.

Save the space page:  boom!

After much tracing, I see the "culprit" lives in the selector comparison methods.  The selector fired to populate the dropdown properly, but fails to validate that the page being saved in the field came from the same result list...  PageComparison->matches() uses page->path and page->id, but not page->name.  And after all, "/en/processwire/access/roles/space-owner/" is not equal to "space-owner".  I'm not sure what the fix is, but it's not symmetrical that the exit test fails for a match that succeeded.

I see 2 workarounds.

1) change the selector to use the path, but then it's dependent on languages, like so:

roles=/en/processwire/access/roles/space-owner/|/fr/processwire/access/roles/space-owner/

or,

2) forgo the elegance of using "role" as a flag on the user and add a checkbox field to the user template to indicate who's a space-owner....   And still assign the user role to space-owner for real access reasons.

Thanks for reading this through. I think it's a defect.

Link to comment
Share on other sites

Soma, thanks for following up.

You're right, it works with ID. I can see it in the PageComparison code.  It does boil down to the fact that the selector roles=name can find the role in question, but the selector->match.... logic ends up comparing role-path with role->name and fails.

This solution is better than enumerating the role paths when there are is than one language.  And it's better than adding an extra checkbox field to the user.  

So, big thanks.

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

×
×
  • Create New...