I have the following Relationships
ONE Dog to MANY Sessions
MANY Dogs to MANY Groups
MANY Sessions to MANY Groups
On the "Dog" page, that Dog can be connected to any number of Groups
On the "Dog" page, Sessions can be added for that particular Dog
I have a form on the Session page that allows the user to connect that current Session with a Group. Currently, the drop-down contains all Groups. I would like it to only contain Groups that belong to the Dog-Group relationship (of the Dog that owns the Session).
I don't know how to limit the drop-down on the form (connect a Group to this Session) to only those Groups related to the Dog that "owns" the Session.
Thanks in advance for any help you can give me.
Hello and thank you for contacting the Toolset support.
The only restriction that can be made in an M2M relationship field is by the author. The field will display only groups created by the same author as the current session. For example:
[cred_field field='@group-session.parent' select_text='--- not set ---' class='form-control' output='bootstrap' author='$current']
The author='$current' attribute can also be used on the cred-relationship-role shortcode.
https://toolset.com/documentation/programmer-reference/forms/cred-shortcodes/
Otherwise, this will need to use a generic field, populate the possible values using a shortcode, then saving the relationship after the form submit using a custom hook. The example shared in this reply should explain the idea better and give some inspiration. It's for a different use case, but it shows how to use Toolset relationship functions:
https://toolset.com/forums/topic/parent-cant-be-identified-without-grandparent/#post-1200437
Saving the relationship may require hooking into the cred_save_data and connecting posts using Toolset functions:
- https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
- https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/
I hope this helps. Let me know if you have any questions.
Thanks so much for this answer. I will have to dig into it and see how it goes. I'll let you know if I have additional questions. Cheers!