Index: trunk/phase3/resources/jquery/jquery.suggestions.js |
— | — | @@ -66,20 +66,26 @@ |
67 | 67 | }, |
68 | 68 | /** |
69 | 69 | * Ask the user-specified callback for new suggestions. Any previous delayed call to this function still pending |
70 | | - * will be canceled. If the value in the textbox hasn't changed since the last time suggestions were fetched, this |
| 70 | + * will be canceled. If the value in the textbox is or hasn't changed since the last time suggestions were fetched, this |
71 | 71 | * function does nothing. |
72 | 72 | * @param {Boolean} delayed Whether or not to delay this by the currently configured amount of time |
73 | 73 | */ |
74 | 74 | update: function( context, delayed ) { |
75 | | - // Only fetch if the value in the textbox changed |
| 75 | + // Only fetch if the value in the textbox changed and is not empty |
76 | 76 | function maybeFetch() { |
77 | | - if ( context.data.$textbox.val() !== context.data.prevText ) { |
| 77 | + if ( ( context.data.$textbox.val().length != 0 ) && ( context.data.$textbox.val() !== context.data.prevText ) ) { |
78 | 78 | context.data.prevText = context.data.$textbox.val(); |
79 | 79 | if ( typeof context.config.fetch == 'function' ) { |
80 | 80 | context.config.fetch.call( context.data.$textbox, context.data.$textbox.val() ); |
81 | 81 | } |
82 | 82 | } |
83 | 83 | } |
| 84 | + |
| 85 | + // clear result div if the value in the text is empty |
| 86 | + if ( context.data.$textbox.val().length != 0 ) { |
| 87 | + context.data.$container.hide(); |
| 88 | + } |
| 89 | + |
84 | 90 | // Cancel previous call |
85 | 91 | if ( context.data.timerID != null ) { |
86 | 92 | clearTimeout( context.data.timerID ); |