Skip Navigation

[Resolved] Dropdown with relationship

This support ticket is created 5 years, 2 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
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 4 replies, has 2 voices.

Last updated by Beda 5 years, 2 months ago.

Assisted by: Beda.

Author
Posts
#1384683

Tell us what you are trying to do?
I have customers, that have HVAC equipment and I'm trying to keep track of maintenance.

I have a form their service technician will be filling out. The first field on the form is a dropdown of all the customers. The technician will choose a customer and that creates the relationship between the customer(custom field) and the visit (custom field). Then all the other fields can be filled in. It works great.
The one thing I'd like is for ONLY the equipment that THAT customer owns would show in the equipment dropdown, otherwise that dropdown will get way too big.
It may be called a dependent field...I'm just not sure how to approach it.

What is the link to your site?
hidden link

your help is appreciated!

#1384869

There are only very few such features in Toolset forms, and mainly, in Relationship Fields

So for example if you have a Toolset Form that connects posts to other posts which you pick from the parent post picker, then that select field could be narrowed to show only posts of the current user (author)

But there are no methods to filter this further by specific fields or users.

What a possible approach is, is to create a Generic Field Select and populate that field with a View.
The View should query and return only those Posts you want to be shown on the form (for example, by user XY or by current user).
Then the View should return a "raw" loop output that is valid JSON, you can do that by choosing the "List with separators" output method in the Loop Wizard when creating the Views loop.

That View should then also have the "Disable the wrapping DIV around the View" checked (it's just below the Loop Editor), and later inserted in the Generic Field Select as the "shortcode to populate the field" (you can insert that when creating the Generic Field.
You would have to use Expert Mode when editing the Toolset Form for that.

I am not sure it will help you because I have not yet a clear picture of what precise posts or fields you want to connect, but it could be a solution.

If not, please can you elaborate on the steps you took, or eventually show me the Form and contents on your site's backend?
I have enabled a private reply for that case.

#1385539

I understand your suggestion about the view displayed in json, but the problem I'm having is that the first
two fields are establishing the relationship between the maintenance visit and the customer, and the maintenance visit and the equipment (unit). A generic field populated by the json view (as you suggested) will not have a parent until that is established by the first dropdown. I want the unit to be narrowed down to only the units of the chosen customer in the first field.
Here is the link to the form: hidden link
let me know if looking at the back end would help, I'm okay with you having access. The site is a dev site.

I would appreciate it if you look at my setup and offer any suggestions.

#1386671

Custom fields do not establish relationships in Toolset.
Post Relationships or Post Reference Fields do.
If you mean that you have a common Post Field that somehow establishes an internal relationship to some other field, then Toolset cannot "know" that, and cannot handle it accordingly as a "related" post or content.

Also there is no way to narrow one field (no matter if when editing, creating or displaying content) in the select options according another Custom Field.
As previously mentioned the only "fields" (or better: inputs) that allow such "narrow down" process are Relationship Fields in Toolset Forms, and those only by Authors, not by anything else.

The link you provided requires an .htaccess login - and it can help to look at it even to just confirm it's a Custom Field and not a Post Relationship, so I can for sure confirm what I hint above.
If you could add that in the next private reply, I can look at the form (and eventually the backend at the data involved, if you can link me to that)

Thanks!

#1387947

One suggestion I do have is to keep the software up to date
All the Toolset and other plugins are out of date, and often Plugins will also update security features, not only "normal features", so does WordPress.
Often after the updates security issues are disclosed, leaving your site (if outdated) exposed.
That's one main reason to update, the other is functionality and bug-resolving.

Now, about the form
Those are not custom fields (Customer and Visit)
Also I am actually not seeing a "Visit" input, only a "Customer" one.
The other one is "Equipment"
Those 2 inputs (Customer and Equipment) are "Post Relationships".

I think "Visit" is actually the Equipment input, as I can see in the backend of the form, you used the Label Customer and Equipment for the Post Relationship inputs "Units Visits" and "Customers Visits"

As I elaborated before and as you can see in those respective inputs when editing the Form, the available items there can be ordered and filtered, but only by author.
You can order the items in the drop down (Select2 input) by title, ID and date, Asc or Desc, and Filter them by the author (either logged in author or any author).
So basically you cannot apply any other filtering there.

There is also no API (officially) that allows to further narrow down that list in the Select2 Inputs.
You should ask for it by suggesting this as a feature at https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/

There are custom code solutions you can use to filter those Select2 Parent Post Select inputs better, but that requires understanding of PHP and the WordPress query, and we cannot guarantee it's proceeded functionality as this is not a public API.
I added such a code example here and you can also see it here and here:
https://toolset.com/forums/topic/how-to-show-in-cred-parent-selector-only-posts-of-logged-in-user/page/2/#post-605405
https://toolset.com/forums/topic/filter-post-relationship-dropdown-by-taxonomy/#post-1220408
hidden link

However, that is custom code we cannot assist, in this scale.

I do hope this helps, as I understand the requirement, however there is no "inbuilt" way to do this.

Unless of course, with the forehead mentioned "Views" that populate generic fields, but then you will need custom code to actually update the relationship of the posts according to the posts picked in those generic fields, leaving you at the same spot of requiring Custom Code for this.