danielfarrell / bootstrap-combobox

A combobox plugin that works with twitter bootstrap
849 stars 328 forks source link

Consider adding minimum search/lookup length. #236

Open cdriver1 opened 7 years ago

cdriver1 commented 7 years ago

Please consider adding a minimum search length for use cases when there is a large number of options and now async calls are available to populate the list. For example I have a list of ~ 2700 employees that is used in conjunction with this combobox and it behaves quite slowly when only one character is entered. Also, when the minimum length is not met the dropdown could be hidden if not shown due to clicking the caret span.

I have implemented this partially myself by adding cases for delete and backspace and changing the default case in the keyup function like so:

   keyup: function (e) {
       // other cases here
       case 8: // backspace
          if (this.$element.val().length < this.minSearchLength) {
              this.hide();
              break;
          } else {
              // fall through to default case.
          }
      case 46: // delete
          if (this.$element.val().length < this.minSearchLength) {
              this.hide();
              break;
          } else {
              // fall through to default case.
          }
      default:
          if (this.$element.val().length > this.minSearchLength-1) {
              this.clearTarget();
              this.lookup();
          }
 }
seanVonDrake commented 6 years ago

I think this could be a really useful feature in case of large datasets; I'd love it

elisamuel40 commented 3 years ago

this would be great