Passer la navigation

[Résolu] Is it possible to filter out a value from a select2 in a relationship form

Ce fil est résolu. Voici une description du problème et la solution proposée.

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 support ticket is created Il y a 4 years. 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 -

Fuseau horaire du supporter : Asia/Karachi (GMT+05:00)

Ce sujet contient 2 réponses, a 2 voix.

Dernière mise à jour par trulsD Il y a 4 years.

Assisté par: Waqar.

Auteur
Publications
#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

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!