Dear Sir/Madam,
I have a user role "Sales", custom post "Dealer", there is a custom field "Sales" associated with the custom post "Dealer".
I want to create a CRED form and hope the customer can select the list of user with role "Sales" to the custom field "Sales"
I temporary add the options in the custom field for selection. How can I do it automatically?
Best regards,
Kelvin.
This is not possible.
What you can do is either manually populate such field and insert it in either the backend or a form (toolset form) of the post so users can pick one or several values each post, or, you can use this approach to relate users to posts:
https://toolset.com/documentation/post-relationships/how-to-create-custom-searches-and-relationships-for-users/
But this is a Post Type relationship, which will eventually not fit your needs.
Another approach can be to contact a Toolset Contractor and custom code the field you mention so it's populated with a row of existing users:
https://toolset.com/contractors/
Dear Beda,
Many thanks for your advice, I think can I use the generic field and write some code to build a dropdown list for selection? What is the output format to the dropdown list for the generic field?
Best regards,
Kelvin.
Here we talk about Toolset Forms then (generic Fields)
Those fields accept valid JSON input as they state in their GUI.
This can meanwhile even be done with Toolset Views.
So you'd set up a Toolset View and produce a valid JSON output as the Toolset generic Field requires, and use that View as a shortcode to populate the Forms field.
Dear Beda,
Yes, I do remember I have a ticket about this, there was some trick when building the JSON, how can I search it back as I have too many tickets.
Dear Beda,
I found the ticket, https://toolset.com/forums/topic/fill-cred-field-by-selecting-type-custom-post/
May I keep this open till I solve it?
Best regards,
Kelvin.
That ticket is very old, it is outdated.
Now you can simply check a box at the bottom of the view's loop editor to make the view raw.
This ticket here will stay open until the Toolset Cleanup robot will iterate it, and remind you of it.
If you comment, it will again stay open a while long, and so on.
Thanks!
Dear Beda,
Do you mean I should make a View to list out all the user_id with a selected role and then put it into the CRED form as a dropdown selection?
Now you can simply check a box at the bottom of the view's loop editor to make the view raw.
I can't find the check box at the bootom of the View's loop editor you mentioned, could you instruct me how?
Best regards,
Kelvin.
It is the checkbox "Disable wrapping DIV" that you see just below the Loop Editor (also visible on the Screenshot)
As you found earlier Generic Fields can be populated with JSON and JSON can be produced with Views if using the Wizard and choosing "List with separators" output mode.
Then make sure the Loop Content is actually generating the exact syntax as suggested by Toolset Forms.
For example, you can output a User Name as the label and a User ID as the value in the syntax and then use that View to populate your generic field to save that (with custom code applied to cred_save_data) in the database against the post.