File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -47,6 +47,9 @@ $(function () {
4747 } ,
4848 onHint : function ( hint ) {
4949 $ ( '#autocomplete-ajax-x' ) . val ( hint ) ;
50+ } ,
51+ onInvalidateSelection : function ( ) {
52+ $ ( '#selction-ajax' ) . html ( 'You selected: none' ) ;
5053 }
5154 } ) ;
5255
Original file line number Diff line number Diff line change 100100 } ;
101101 that . hint = null ;
102102 that . hintValue = '' ;
103+ that . selection = null ;
103104
104105 // Initialize and set options:
105106 that . initialize ( ) ;
178179 that . el . on ( 'keyup.autocomplete' , function ( e ) { that . onKeyUp ( e ) ; } ) ;
179180 that . el . on ( 'blur.autocomplete' , function ( ) { that . onBlur ( ) ; } ) ;
180181 that . el . on ( 'focus.autocomplete' , function ( ) { that . fixPosition ( ) ; } ) ;
182+ that . el . on ( 'change.autocomplete' , function ( e ) { that . onKeyUp ( e ) ; } ) ;
181183 } ,
182184
183185 onBlur : function ( ) {
347349 return ;
348350 }
349351
350- that . findBestHint ( ) ;
351-
352352 clearInterval ( that . onChangeInterval ) ;
353353
354354 if ( that . currentValue !== that . el . val ( ) ) {
355+ that . findBestHint ( ) ;
355356 if ( that . options . deferRequestBy > 0 ) {
356357 // Defer lookup in case when value changes very quickly:
357358 that . onChangeInterval = setInterval ( function ( ) {
367368 var that = this ,
368369 q ;
369370
371+ if ( that . selection ) {
372+ that . selection = null ;
373+ ( that . options . onInvalidateSelection || $ . noop ) ( ) ;
374+ }
375+
370376 clearInterval ( that . onChangeInterval ) ;
371377 that . currentValue = that . el . val ( ) ;
372378
654660 that . el . val ( that . currentValue ) ;
655661 that . signalHint ( null ) ;
656662 that . suggestions = [ ] ;
663+ that . selection = suggestion ;
657664
658665 if ( $ . isFunction ( onSelectCallback ) ) {
659666 onSelectCallback . call ( that . element , suggestion ) ;
You can’t perform that action at this time.
0 commit comments