File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -319,9 +319,14 @@ var Dataset = (function() {
319319 pending : templates . pending && _ . templatify ( templates . pending ) ,
320320 header : templates . header && _ . templatify ( templates . header ) ,
321321 footer : templates . footer && _ . templatify ( templates . footer ) ,
322- suggestion : templates . suggestion || suggestionTemplate
322+ suggestion : templates . suggestion ? userSuggestionTemplate : suggestionTemplate
323323 } ;
324324
325+ function userSuggestionTemplate ( context ) {
326+ var template = templates . suggestion ;
327+ return $ ( template ( context ) ) . attr ( "id" , _ . guid ( ) ) ;
328+ }
329+
325330 function suggestionTemplate ( context ) {
326331 return $ ( '<div role="option">' ) . attr ( 'id' , _ . guid ( ) ) . text ( displayFn ( context ) ) ;
327332 }
Original file line number Diff line number Diff line change @@ -421,6 +421,33 @@ describe('Dataset', function() {
421421 } ) ;
422422 } ) ;
423423
424+ it ( 'should apply id attribute when using default suggestion template' , function ( ) {
425+ this . dataset = new Dataset ( {
426+ source : this . source ,
427+ node : $ ( '<div>' ) ,
428+ } , www ) ;
429+
430+ this . source . andCallFake ( syncMockSuggestions ) ;
431+ this . dataset . update ( 'woah' ) ;
432+
433+ expect ( this . dataset . $el . find ( 'div[role="option"]' ) ) . toHaveAttr ( 'id' ) ;
434+ } ) ;
435+
436+ it ( 'should apply id attribute when using custom suggestion template' , function ( ) {
437+ this . dataset = new Dataset ( {
438+ source : this . source ,
439+ node : $ ( '<div>' ) ,
440+ templates : {
441+ suggestion : function ( c ) { return '<p class="search-result"> result' + c . query + '</p>' ; }
442+ }
443+ } , www ) ;
444+
445+ this . source . andCallFake ( syncMockSuggestions ) ;
446+ this . dataset . update ( 'woah' ) ;
447+
448+ expect ( this . dataset . $el . find ( 'p.search-result' ) ) . toHaveAttr ( 'id' ) ;
449+ } ) ;
450+
424451 describe ( '#clear' , function ( ) {
425452 it ( 'should clear suggestions' , function ( ) {
426453 this . source . andCallFake ( syncMockSuggestions ) ;
You can’t perform that action at this time.
0 commit comments