MultiComboBox.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dojox.form.MultiComboBox"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.form.MultiComboBox"] = true;
  8. dojo.provide("dojox.form.MultiComboBox");
  9. dojo.experimental("dojox.form.MultiComboBox");
  10. dojo.require("dijit.form.ComboBox");
  11. dojo.require("dijit.form.ValidationTextBox");
  12. dojo.declare("dojox.form.MultiComboBox",
  13. [dijit.form.ValidationTextBox, dijit.form.ComboBoxMixin],{
  14. //
  15. // summary: A ComboBox that accpets multiple inputs on a single line?
  16. //
  17. // delimiter: String
  18. // The character to use to separate items in the ComboBox input
  19. delimiter: ",",
  20. _previousMatches: false,
  21. _setValueAttr: function(value){
  22. if (this.delimiter && value.length != 0){
  23. value = value+this.delimiter+" ";
  24. arguments[0] = this._addPreviousMatches(value);
  25. }
  26. this.inherited(arguments);
  27. },
  28. _addPreviousMatches: function(/* String */text){
  29. if(this._previousMatches){
  30. if(!text.match(new RegExp("^"+this._previousMatches))){
  31. text = this._previousMatches+text;
  32. }
  33. text = this._cleanupDelimiters(text);
  34. }
  35. return text; // String
  36. },
  37. _cleanupDelimiters: function(/* String */text){
  38. if(this.delimiter){
  39. text = text.replace(new RegExp(" +"), " ");
  40. text = text.replace(new RegExp("^ *"+this.delimiter+"* *"), "");
  41. text = text.replace(new RegExp(this.delimiter+" *"+this.delimiter), this.delimiter);
  42. }
  43. return text;
  44. },
  45. _autoCompleteText: function(/* String */text){
  46. arguments[0] = this._addPreviousMatches(text);
  47. this.inherited(arguments);
  48. },
  49. _startSearch: function(/* String */text){
  50. text = this._cleanupDelimiters(text);
  51. var re = new RegExp("^.*"+this.delimiter+" *");
  52. if((this._previousMatches = text.match(re))){
  53. arguments[0] = text.replace(re, "");
  54. }
  55. this.inherited(arguments);
  56. }
  57. });
  58. }