I use the following view with to show and remove a connection between two posts:
<div class="row" id="connected-[wpv-post-id]">
<div class="col-md-10 col-sm-10 col-xs-10" style="position: relative;">
<span class="actions">#[wpv-post-id] - [wpv-post-title]</span>
</div>
<div class="col-md-2 col-sm-2 col-xs-2">
[cred-delete-relationship role_items='$fromViews' relationship='profil-nfc-chip' redirect='self' class='disconnect']<span class="dashicons dashicons-remove" title="Entfernen"></span>[/cred-delete-relationship]
</div>
</div>
Nonetheless, I would prefer this to happen via ajax. It want an ajax function that removes the line with the id "connected-[wpv-post-id]" after processing the disconnection. It would work like this example.
jQuery('.disconnect').click(function() {
//replace remove-icon with loading animation
jQuery(this).html('<div class="lds-dual-ring dark"></div>');
//if Ajax succes: get the ID of the clicked element and delete the row
//var id = jQuery(this).attr('data-relateditemtwo');
//jQuery("#connected-"+id).remove();
//endif
});
But unfortunately, adding this jQuery breaks the functionality of the cred-delete-relationship shortcode. It shows the loader but not even the page refresh happens. Also, I would need the second part to only fire after the disconnection is processed. Any idea?
EDIT: Can s.o. please correct my title, there is a not so nice typo...
Hello and thank you for contacting the Toolset support.
This Toolset shortcode does not support AJAX calls, it will always reload the page, or redirect to a different page. If you believe this should support AJAX, please suggest it here https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/
If you want to implement this with AJAX, you will have to create your own AJAX action and handler and call it with Javascript code. Check these articles:
- versteckter Link
- versteckter Link
You can use the toolset_disconnect_posts function from our Relationship API https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_disconnect_posts
I hope this answers your request. Let me know if you have any questions.