Skip Navigation

[Resolved] Is it possible to filter out a value from a select2 in a relationship form

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

Problem:
The customer asked if it was possible to exclude a value in a select2 dropdown on a relationship form based on a dynamic value set by a shortcode.

Solution:
Guided there is no built-in feature available for this and will involve creating a custom select field in the form. Also shared a link to another forum thread with a similar solution:
https://toolset.com/forums/topic/dynamic-field-values-from-cpt/

Relevant Documentation:
n/a

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/Karachi (GMT+05:00)

This topic contains 2 replies, has 2 voices.

Last updated by trulsD 1 year, 11 months ago.

Assisted by: Waqar.

Author
Posts
#2373735

I am trying to exclude a value in a select2 dropdown on a relationship form based on a dynamic value set by a shortcode.
Do I have to use jQuery?

Truls

#2373939

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Truls,

Thank you for contacting us and I'd be happy to assist.

There is no built-in feature available for this filtering, so it will require some workaround and code customization.

For example, you can hide the actual relationship selection field using CSS code and generate a custom select field through a custom shortcode, that generates the options, based on the desired criteria.

Once the custom select field is added, you can include some custom script to initialize the 'select2' dropdown on this field and to automatically select the option in the hidden relationship field, that is selected in this custom select field, on the change event.

You'll find the example usage of this approach for a similar requirement, in this support thread:
https://toolset.com/forums/topic/dynamic-field-values-from-cpt/

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#2374653

My issue is resolved now. Thank you!

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