File tree Expand file tree Collapse file tree 3 files changed +38
-3
lines changed Expand file tree Collapse file tree 3 files changed +38
-3
lines changed Original file line number Diff line number Diff line change 472
472
className : $elm . prop ( 'class' ) ,
473
473
text : $elm . html ( ) ,
474
474
slug : $ . trim ( _this . utils . replaceDiacritics ( $elm . html ( ) ) ) ,
475
+ alt : $elm . attr ( 'data-alt' ) ,
475
476
selected : $elm . prop ( 'selected' ) ,
476
477
disabled : isDisabled
477
478
} ;
627
628
if ( val . length ) {
628
629
// Search in select options
629
630
$ . each ( _this . items , function ( i , elm ) {
630
- if ( ! elm . disabled && searchRegExp . test ( elm . text ) || searchRegExp . test ( elm . slug ) ) {
631
+ if ( elm . disabled ) {
632
+ return ;
633
+ }
634
+ if ( searchRegExp . test ( elm . text ) || searchRegExp . test ( elm . slug ) ) {
631
635
_this . highlight ( i ) ;
632
636
return ;
633
637
}
638
+ if ( ! elm . alt ) {
639
+ return ;
640
+ }
641
+ var altItems = elm . alt . split ( '|' ) ;
642
+ for ( var ai = 0 ; ai < altItems . length ; ai ++ ) {
643
+ if ( ! altItems [ ai ] ) {
644
+ break ;
645
+ }
646
+ if ( searchRegExp . test ( altItems [ ai ] . trim ( ) ) ) {
647
+ _this . highlight ( i ) ;
648
+ return ;
649
+ }
650
+ }
634
651
} ) ;
635
652
}
636
653
} ) ;
Original file line number Diff line number Diff line change @@ -80,6 +80,24 @@ describe('basic suite', function() {
80
80
expect ( select . val ( ) ) . toBe ( 'banana' ) ;
81
81
} ) ;
82
82
83
+ it ( 'should search alternative text' , function ( ) {
84
+ $ ( '.selectric-input' ) . val ( 'alt banana' ) . trigger ( 'input' ) ;
85
+ $ ( '.selectric-items' ) . find ( '.highlighted' ) . click ( ) ;
86
+ expect ( select . val ( ) ) . toBe ( 'banana' ) ;
87
+ } ) ;
88
+
89
+ it ( 'should search alternative text with separator' , function ( ) {
90
+ $ ( '.selectric-input' ) . val ( 'altberry' ) . trigger ( 'input' ) ;
91
+ $ ( '.selectric-items' ) . find ( '.highlighted' ) . click ( ) ;
92
+ expect ( select . val ( ) ) . toBe ( 'bilberry' ) ;
93
+ } ) ;
94
+
95
+ it ( 'should search alternative text with separator 2' , function ( ) {
96
+ $ ( '.selectric-input' ) . val ( 'another berry' ) . trigger ( 'input' ) ;
97
+ $ ( '.selectric-items' ) . find ( '.highlighted' ) . click ( ) ;
98
+ expect ( select . val ( ) ) . toBe ( 'bilberry' ) ;
99
+ } ) ;
100
+
83
101
it ( 'highlight() should return undefined if index is undefined' , function ( ) {
84
102
expect ( select . data ( 'selectric' ) . highlight ( undefined ) ) . toBe ( undefined ) ;
85
103
} ) ;
Original file line number Diff line number Diff line change 4
4
< option value ="loooooooooooooong-option "> Loooooooooooooong option</ option >
5
5
< option value ="apple "> Apple</ option >
6
6
< option selected value ="apricot "> Apricot</ option >
7
- < option class ="customOptionClass " value ="banana "> Banana</ option >
8
- < option value ="bilberry "> Bilberry</ option >
7
+ < option class ="customOptionClass " value ="banana "data-alt =" alt banana " > Banana</ option >
8
+ < option value ="bilberry " data-alt =" altberry | another berry " > Bilberry</ option >
9
9
< option value ="blackberry "> Blackberry</ option >
10
10
< option value ="blackcurrant "> Blackcurrant</ option >
11
11
< option value ="blueberry "> Blueberry</ option >
You can’t perform that action at this time.
0 commit comments