MultiComboBox.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. define("dojox/form/MultiComboBox", [
  2. "dojo/_base/kernel",
  3. "dijit/form/ValidationTextBox",
  4. "dijit/form/ComboBoxMixin",
  5. "dojo/_base/declare"
  6. ], function(kernel, ValidationTextBox, ComboBoxMixin, declare){
  7. kernel.experimental("dojox.form.MultiComboBox");
  8. /*=====
  9. ValidationTextBox = dijit.form.ValidationTextBox;
  10. ComboBoxMixin = dijit.form.ComboBoxMixin;
  11. =====*/
  12. return declare("dojox.form.MultiComboBox", [ValidationTextBox, ComboBoxMixin],{
  13. // summary:
  14. // A ComboBox that accepts multiple inputs on a single line
  15. // delimiter: String
  16. // The character to use to separate items in the ComboBox input
  17. delimiter: ",",
  18. _previousMatches: false,
  19. _setValueAttr: function(value){
  20. if(this.delimiter && value.length != 0){
  21. value = value+this.delimiter+" ";
  22. arguments[0] = this._addPreviousMatches(value);
  23. }
  24. this.inherited(arguments);
  25. },
  26. _addPreviousMatches: function(/* String */text){
  27. if(this._previousMatches){
  28. if(!text.match(new RegExp("^"+this._previousMatches))){
  29. text = this._previousMatches+text;
  30. }
  31. text = this._cleanupDelimiters(text);
  32. }
  33. return text; // String
  34. },
  35. _cleanupDelimiters: function(/* String */text){
  36. if(this.delimiter){
  37. text = text.replace(new RegExp(" +"), " ");
  38. text = text.replace(new RegExp("^ *"+this.delimiter+"* *"), "");
  39. text = text.replace(new RegExp(this.delimiter+" *"+this.delimiter), this.delimiter);
  40. }
  41. return text;
  42. },
  43. _autoCompleteText: function(/* String */text){
  44. arguments[0] = this._addPreviousMatches(text);
  45. this.inherited(arguments);
  46. },
  47. _startSearch: function(/* String */text){
  48. text = this._cleanupDelimiters(text);
  49. var re = new RegExp("^.*"+this.delimiter+" *");
  50. if((this._previousMatches = text.match(re))){
  51. arguments[0] = text.replace(re, "");
  52. }
  53. this.inherited(arguments);
  54. }
  55. });
  56. });