Skip Navigation

[Resolved] Dynamically select value of a Select Field based on the selection of another fie

This thread is resolved. Here is a description of the problem and solution.

Problem:

Setup post type relationship filters in Toolset post form.

Solution:

There isn't such kind of built-in feature within Toolset Forms plugin.

But there is a workaround here:

https://toolset.com/forums/topic/dynamically-select-value-of-a-select-field-based-on-the-selection-of-another-fie/#post-1775209

Relevant Documentation:

https://toolset.com/documentation/post-relationships/selecting-parent-posts-using-forms-create-child-items/

This support ticket is created 3 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 6 replies, has 2 voices.

Last updated by Mukesh 3 years, 7 months ago.

Assisted by: Luo Yang.

Author
Posts
#1769519

Tell us what you are trying to do?
I'm would like to use CRED Post Form where I will have an Attorney select field, along with a Hospital, Pharmacy and Urgent Care select fields. All four select fields are populated with CPTs. Once the Attorney is selected, I would like the Hospital, Pharmacy and Urgent Care to dynamically select value from their respective options in their Select field. I am keeping the relationship of an Attorney to Hospital,Pharmacy and Urgent care so based on that Attorney selected the other three fields will show respective selections.

Is there any documentation that you are following?
I search through existing posts and found one similar but that was more than 1 year ago so hoping there is some solution now through custom code or AJAX etc.
Post I found: https://toolset.com/forums/topic/select-fields-that-change-based-on-choices-above/

Is there a similar example that we can see?
I haven't found any similar use case.

What is the link to your site?
hidden link however I haven't build out the CRED Post form yet.

Minesh has helped with this project in the past, and I would not mind if he can be assigned again.

#1770077

Hello,

There isn't such kind of built-in feature within Toolset Forms plugin.

How do you setup post types and the post type relationships?
How do you setup the post form?
Please elaborate the questions with more details, I need to test it in my localhost, and check if there is any other workaround, thanks

#1772259

Hi Luo,

I haven't setup the post types yet, but I'm thinking of having custom post types for Attorney, Hospital, Pharmacy and Urgent Care.
Then I was thinking of setting up CRED Form to add/update Attorney. On that form, I would have Select dropdowns for Hospital, Pharmacy and Urgent Care so the Admin can set the "mapping" for an Attorney. Basically these mappings are preferences. Then when the end-user using another CRED Form which has Select fields for Attorney, Hospital, Pharmacy and Urgent Care, creates normal Posts, they would pick the Attorney (select dropdown) the AJAX call or something would automatically select the Hospital , Pharmacy and Urgent Care (based on the Admin's mapping). The end user can leave those as is or select an override. DOes that make sense?

Thanks,
Mukesh

#1772817

Since you did not provide the post type relationships settings, so I assume these:
1) Four post types in your website:
Attorney, Hospital, Pharmacy, Urgent Care
2) One-to-many relationship between Hospital and Pharmacy
One-to-many relationship between Pharmacy and Urgent Care
One-to-many relationship between Urgent Care and Attorney

You can try these:
1) Create new "Attorney" post:
Setup a post view:
- Query "Urgent Care" posts
- setup a search form filter the result by post type relationships: Hospital, Pharmacy
https://toolset.com/course-lesson/creating-a-custom-search/
- In view's loop, display a child form link for creating new "Attorney" post
https://toolset.com/documentation/post-relationships/selecting-parent-posts-using-forms-create-child-items/

2) Edit "Attorney" post
Same as above, setup a post view:
- Query "Attorney" posts
- setup a search form filter the result by: Hospital, Pharmacy and Urgent Care
https://toolset.com/course-lesson/creating-a-custom-search/
- In view's loop, display a edit post form link for editing "Attorney" post
https://toolset.com/course-lesson/front-end-forms-for-editing-content/

For your reference.

#1773299

Hi Lou, I don't believe you understood the use case. Perhaps I was not clear so let me try another way to explain.

Custom Post Types:
1. Attorney
2. Hospital
3. Pharmacy
4. Urgent Care

Relationships - An Attorney Post Type would have one of each Hospital, Pharmacy and Urgent Care assigned to it. e.g. Law Office of Toolset has ABC Hospital, XYZ Pharmacy and NNN Urgent Care assigned (or mapped) to it. This mapping/assignment will be done via a CRED POST FORM that I will setup for the Attorney Post type. So the Attorney Post Type will have the following fields: Name (text), Hospital Assigned (Select Field with posts from Hospital Post type), Pharmacy Assigned (Select Field with posts from Pharmacy Post type), Urgent Care Assigned (Select Field with posts from Urgent Care Post Type).

I will have an ADMIN user be able to add new Attorney's using the CRED POST FORM I just mentioned.

Then I will have end-users that will create new POSTS. On their CRED POST FORM I will have a Select Field with list of all Attorney posts. I will also have 3 more Select Fields, each for the Hospital, Pharmacy, Urgent Care. All three of those are Select fields with list of each of their posts respectively. SO on this posts CRED FORM (for end users) they will select Attorney from the list. e.g. they select Law Office of Toolset. Then what my requirement is that the 3 Select fields (Hospital, Pharmacy and Urgent Care) will auto-select the Assigned values (based on what the Admin setup using the Attorney CRED POST FORM I mentioned). Does that make sense now? Let me know which part is not clear of this use case.

Note that any single Hospital, Pharmacy or Urgent Care can be "Assigned" to multiple Attorneys. So just like the example of Law Office of Toolset , I could have another Attorney e.g. Law Office of LOU can be assigned the same Hospital, Pharamcy and Urgent Care.

Thanks
Mukesh

#1775209

It is still not clear.

For the question "Then I will have end-users that will create new POSTS..."

Are you going to setup a post for for creating WordPress built-in post type "Posts"?

If it is, is there any relationship between "Posts" and "Attorney"?

In your case, I suggest try these:
1) setup one-to-many relationship between "Attorney" and "Posts".
2) Create a post view with search form:
- Query "Attorney" post
- Filter by relationships:
Hospital
Pharmacy
Urgent Care
https://toolset.com/course-lesson/creating-a-custom-search/
- In view's loop, display a child post form link for creating new "Post"
https://toolset.com/documentation/post-relationships/selecting-parent-posts-using-forms-create-child-items/

So user can search and get "Attorney" post, and create related post

3) In single post content, you can follow our document to display the grandparent post information:
Hospital
Pharmacy
Urgent Care
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/displaying-fields-of-grandparents/

#1780031

I'm going to figure out a JQuery/Ajax solution with the WordPress built-in Ajax methods.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.