Hi
I have a form with a relationship dropdown field to select a post.
If the result is "No results found" I'd like to have a "add" button next to the field in order to open a new window and add the missing post.
Is there a "native code option" to do that ? Or I need to detect that "no result" sentence with JS to display a "add" button ?
Hi,
Welcome to Toolset support. There’s no built-in “show an Add button when the relationship dropdown says ‘No results found’ ” option in Toolset.
This will need custom code, which is outside of our support scope. One thing that might work is that you change the No result option with some sort of button that you can control via JS. Because the relationship selector is Select2, you can watch its events and append a button when the “no results” message appears. Example:
jQuery(function($){
var $sel = $('select.cred-relationship-role-child'); // adjust selector
$sel.on('select2:open', function(){
setTimeout(function(){
var $drop = $('.select2-container--open .select2-results');
var $msg = $drop.find('.select2-results__message');
if ($msg.length && !$drop.find('.js-add-related').length) {
$('<a class="js-add-related" target="_blank" href="/add-company/?return=' +
encodeURIComponent(location.href) + '">+ Add new Company</a>')
.css({display:'block', padding:'8px'})
.appendTo($drop);
}
}, 0);
});
});
This isn’t an official Toolset setting; it’s just JS on top of the existing control.
Thanks.