66    < link  rel ="stylesheet " href ="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css "> 
77    < script  src ="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js "> </ script > 
88    < script  src ="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js "> </ script > 
9-     < script  src ="https://rawgit.com/jshjohnson/Choices/v7.0.0 /public/assets/scripts/choices.js "> </ script > 
9+     < script  src ="
https://cdn.jsdelivr.net/npm/[email protected]  /public/assets/scripts/choices.js "
> </ script >  1010    < script  src ="dist/choicesjsstencil.js "> </ script > 
1111    < style > 
1212      html  {
@@ -85,10 +85,6 @@ <h2 class="col-sm-12">ChoicesJS Web Component: test page</h2>
8585            < div  class ="pull-left values-container "> 
8686              < p  class ="values-container__text "> </ p > 
8787            </ div > 
88-             < div  class ="form-group pull-right "> 
89-               < button  class ="btn btn-primary " type ="submit "> Apply</ button > 
90-               < button  class ="btn btn-default " type ="reset "> Reset</ button > 
91-             </ div > 
9288          </ div > 
9389        </ div > 
9490        < div  class ="row "> 
@@ -102,6 +98,8 @@ <h2 class="col-sm-12">ChoicesJS Web Component: test page</h2>
10298                < option  value ="single "> Single</ option > 
10399                < option  value ="multiple "> Multiple</ option > 
104100              </ select > 
101+               < button  class ="btn btn-primary " type ="submit "> Apply</ button > 
102+               < button  class ="btn btn-default " type ="reset "> Reset</ button > 
105103              < div  class ="pull-right "> 
106104                < button  class ="btn btn-info " type ="button " data-toggle ="modal " data-target ="#customSearchModal "> Search options</ button > 
107105                < button  class ="btn btn-success " type ="button " data-toggle ="modal " data-target ="#customStylesModal "> Custom Styles</ button > 
@@ -499,7 +497,7 @@ <h2 class="col-sm-12">ChoicesJS Web Component: test page</h2>
499497              </ textarea > 
500498              < label  for ="callbackOnCreateTemplates "> }</ label > 
501499              < br /> 
502-               < a  href ="https://github.com/jshjohnson/Choices/blob/v7 .0.0 /public/assets/scripts/choices.js#L713-L788  " target ="_blank "> 
500+               < a  href ="https://github.com/jshjohnson/Choices/blob/v9 .0.1 /public/assets/scripts/choices.js#L2777-L2926  " target ="_blank "> 
503501                Templates reference
504502              </ a > 
505503            </ div > 
@@ -525,7 +523,7 @@ <h2 class="col-sm-12">ChoicesJS Web Component: test page</h2>
525523          < div  class ="col-md-12 "> 
526524            < p  class ="text-center pad-top "> 
527525              See full documentation in
528-               < a  href ="https://www.npmjs.com/package/choices.js/v/7 .0.0  " target ="_blank "> choices.js</ a > 
526+               < a  href ="https://www.npmjs.com/package/choices.js/v/9 .0.1  " target ="_blank "> choices.js</ a > 
529527              npm package.
530528            </ p > 
531529          </ div > 
@@ -579,7 +577,7 @@ <h4 class="modal-title">Custom Styles</h4>
579577    "openState": "is-open",
580578    "disabledState": "is-disabled",
581579    "highlightedState": "is-highlighted",
582-     "hiddenState ": "is-hidden ",
580+     "selectedState ": "is-selected ",
583581    "flippedState": "is-flipped",
584582    "loadingState": "is-loading",
585583    "noResults": "has-no-results",
@@ -626,6 +624,24 @@ <h5 class="text-center pad-bottom">
626624                        < span  class ="glyphicon glyphicon glyphicon-question-sign "> </ span > 
627625                      </ span > 
628626                    </ div > 
627+                     < div  class ="form-group "> 
628+                       < label  for ="includeMatches "> 
629+                         Include matches
630+                         < input  type ="checkbox " name ="includeMatches "> 
631+                       </ label > 
632+                       < span  class ="description " data-toggle ="tooltip " title ="Whether the matches should be included in the result set. When true, each record in the result set will include the indices of the matched characters. These can consequently be used for highlighting purposes. "> 
633+                         < span  class ="glyphicon glyphicon glyphicon-question-sign "> </ span > 
634+                       </ span > 
635+                     </ div > 
636+                     < div  class ="form-group "> 
637+                       < label  for ="includeScore "> 
638+                         Include score
639+                         < input  type ="checkbox " name ="includeScore " checked  disabled > 
640+                       </ label > 
641+                       < span  class ="description " data-toggle ="tooltip " title ="Whether the score should be included in the result set. This option is mandatory, Choices.JS uses the score property by default. "> 
642+                         < span  class ="glyphicon glyphicon glyphicon-question-sign "> </ span > 
643+                       </ span > 
644+                     </ div > 
629645                    < div  class ="form-group "> 
630646                      < label  for ="shouldSort "> 
631647                        Sort
@@ -671,6 +687,80 @@ <h5 class="text-center pad-bottom">
671687                        < span  class ="glyphicon glyphicon glyphicon-question-sign "> </ span > 
672688                      </ span > 
673689                    </ div > 
690+                     < div  class ="form-group "> 
691+                       < label  for ="sortFn "> 
692+                         sortFn(a, b) {
693+                       </ label > 
694+                       < span  class ="description " data-toggle ="tooltip " title ="The function that will sort choices and items before they are displayed (unless a user is searching). By default choices and items are sorted by score.<br/><br/>The function takes two parameters: a, b. "> 
695+                         < span  class ="glyphicon glyphicon glyphicon-question-sign "> </ span > 
696+                       </ span > 
697+                       < textarea  class ="form-control textarea--vertical " name ="sortFn " rows ="2 "> 
698+ return a.score - b.score;
699+                       </ textarea > 
700+                       < label  for ="sortFn "> }</ label > 
701+                     </ div > 
702+                     < div  class ="form-group "> 
703+                       < label  for ="getFn "> 
704+                         getFn(obj, path) {
705+                       </ label > 
706+                       < span  class ="description " data-toggle ="tooltip " title ="The get function to use when fetching an object properties. The default will search nested paths *ie foo.bar.baz* "> 
707+                         < span  class ="glyphicon glyphicon glyphicon-question-sign "> </ span > 
708+                       </ span > 
709+                       < textarea  class ="form-control textarea--vertical " name ="getFn " rows ="8 "> 
710+ var list = [];
711+ 
712+ function baseToString(value) {
713+   // Exit early for strings to avoid a performance hit in some environments.
714+   if (typeof value == 'string') {
715+     return value;
716+   }
717+ 
718+   var result = (value + '');
719+   return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
720+ }
721+ 
722+ function toString(value) {
723+   return value == null ? '' : baseToString(value);
724+ }
725+ 
726+ function _get(obj, path) {
727+   if (!path) {
728+     // If there's no path left, we've gotten to the object we care about.
729+     list.push(obj);
730+   } else {
731+     var dotIndex = path.indexOf('.')
732+     var key = path;
733+     var remaining = null;
734+ 
735+     if (dotIndex !== -1) {
736+       key = path.slice(0, dotIndex);
737+       remaining = path.slice(dotIndex + 1);
738+     }
739+ 
740+     var value = obj[key];
741+ 
742+     if (value !== null && value !== undefined) {
743+       if (!remaining && (typeof value === 'string' || typeof value === 'number')) {
744+         list.push(toString(value));
745+       } else if (Array.isArray(value)) {
746+         // Search each item in the array.
747+         for (var i = 0, len = value.length; i <  len ;  i  + = 1)  { 
748+           _get(value[i],  remaining); 
749+         } 
750+       }  else  if  (remaining)  { 
751+         // An object. Recurse further.
752+         _get(value, remaining);
753+       }
754+     }
755+   }
756+ }
757+ 
758+ _get(obj, path);
759+ 
760+ return list;
761+                       </ textarea > 
762+                       < label  for ="getFn "> }</ label > 
763+                     </ div > 
674764                  </ div > 
675765                  < div  class ="col-md-6 "> 
676766                    < div  class ="form-group "> 
@@ -713,6 +803,15 @@ <h5 class="text-center pad-bottom">
713803                      </ span > 
714804                      < input  type ="number " class ="form-control " name ="minMatchCharLength " value ="1 "> 
715805                    </ div > 
806+                     < div  class ="form-group "> 
807+                       < label  for ="findAllMatches "> 
808+                         Find all matches
809+                         < input  type ="checkbox " name ="findAllMatches "> 
810+                       </ label > 
811+                       < span  class ="description " data-toggle ="tooltip " title ="When true, the matching function will continue to the end of a search pattern even if a perfect match has already been located in the string. "> 
812+                         < span  class ="glyphicon glyphicon glyphicon-question-sign "> </ span > 
813+                       </ span > 
814+                     </ div > 
716815                    < div  class ="form-group "> 
717816                      < label  for ="location "> 
718817                        Location
@@ -852,7 +951,13 @@ <h5 class="text-center pad-bottom">
852951            location : Number , 
853952            threshold : Number , 
854953            minMatchCharLength : Number , 
855-             maxPatternLength : Number 
954+             maxPatternLength : Number , 
955+             sortFn : function ( value )  { 
956+               return  new  Function ( 'a' ,  'b' ,  value . trim ( ) ) ; 
957+             } , 
958+             getFn : function ( value )  { 
959+               return  new  Function ( 'obj' ,  'path' ,  value . trim ( ) ) ; 
960+             } 
856961          } ) ; 
857962
858963          console . info ( 'changeSearch' ,  fields ) ; 
@@ -874,7 +979,7 @@ <h5 class="text-center pad-bottom">
874979          var  values  =  [ ] ; 
875980          var  i ,  lng ; 
876981
877-           // forEach is not available in all browsers 
982+           // FormData: forEach()  is not available in all browsers 
878983          if  ( typeof  form . forEach  ===  'function' )  { 
879984            form . forEach ( function ( value ,  name )  { 
880985              values . push ( name  +  ': `'  +  value  +  '`' )  ; 
0 commit comments