diff --git a/src/collective/dms/thesaurus/browser/dmsthesaurus_view.pt b/src/collective/dms/thesaurus/browser/dmsthesaurus_view.pt
index b7cb276..f4c1897 100644
--- a/src/collective/dms/thesaurus/browser/dmsthesaurus_view.pt
+++ b/src/collective/dms/thesaurus/browser/dmsthesaurus_view.pt
@@ -51,20 +51,32 @@ function prep_thesaurus_overlay() {
});
$('.overlay-ajax button').click(function() {
overlay_id = $(this).parents('.overlay-ajax').attr('id');
- field = $('a[rel="#' + overlay_id + '"]').parents('.field');
var id = $(this).parents('.overlay-ajax').data('keyword-id');
var title = $(this).parents('.overlay-ajax').find('h1').text();
- $(field).find('select').append('');
- $(field).find('.selected-options').append('' +
- '' + title + '' +
- '×\n');
- $('span.remove').unbind('click').click(function() {
- var field = $(this).parents('.field');
- var term_id = $(this).parent().attr('data-term-id');
- $(field).find('select option[id=' + term_id + ']').remove();
- $(this).parent().remove();
- });
+ /* when used as a field widget */
+ field = $('a[rel="#' + overlay_id + '"]').parents('.field');
+ if (field) {
+ $(field).find('select').append('');
+ $(field).find('.selected-options').append('' +
+ '' + title + '' +
+ '×\n');
+
+ $('span.remove').unbind('click').click(function() {
+ var field = $(this).parents('.field');
+ var term_id = $(this).parent().attr('data-term-id');
+ $(field).find('select option[id=' + term_id + ']').remove();
+ $(this).parent().remove();
+ });
+ }
+
+ /* when used as a criteria widget */
+ criteria = $('a[rel="#' + overlay_id + '"]').parents('.criteria');
+ if (criteria) {
+ $(criteria).find('input.queryvalue').val(id);
+ $(criteria).find('input.querylabel').val(title);
+ $.querywidget.updateSearch();
+ }
$(this).parents('.overlay-ajax').find('.close').click();
return false;