};
CRM.api3('contact', 'getquick', params).done(function(result) {
var ret = [];
- if (result.values) {
+ if (result.values.length > 0) {
+ $('#sort_name_navigation').autocomplete('widget').menu('option', 'disabled', false);
$.each(result.values, function(k, v) {
ret.push({value: v.id, label: v.data});
- })
+ });
+ } else {
+ $('#sort_name_navigation').autocomplete('widget').menu('option', 'disabled', true);
+ ret.push({value: '0', label: {/literal}'{ts escape='js'}None found.{/ts}'{literal}});
}
response(ret);
})
return false;
},
select: function (event, ui) {
- document.location = CRM.url('civicrm/contact/view', {reset: 1, cid: ui.item.value});
+ if (ui.item.value > 0) {
+ document.location = CRM.url('civicrm/contact/view', {reset: 1, cid: ui.item.value});
+ }
return false;
},
create: function() {
// Place menu in front
- $(this).autocomplete('widget').css('z-index', $('#civicrm-menu').css('z-index'));
+ $(this).autocomplete('widget')
+ .addClass('crm-quickSearch-results')
+ .css('z-index', $('#civicrm-menu').css('z-index'));
}
})
.keydown(function() {
var $menu = $('#sort_name_navigation').autocomplete('widget');
if ($('li.ui-menu-item', $menu).length === 1) {
var cid = $('li.ui-menu-item', $menu).data('ui-autocomplete-item').value;
- document.location = CRM.url('civicrm/contact/view', {reset: 1, cid: cid});
- return false;
+ if (cid > 0) {
+ document.location = CRM.url('civicrm/contact/view', {reset: 1, cid: cid});
+ return false;
+ }
}
});
// Close menu after selecting an item