[483] | 1 | define([ |
---|
| 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 | return declare("dojox.form.MultiComboBox", [ValidationTextBox, ComboBoxMixin],{ |
---|
| 10 | // summary: |
---|
| 11 | // A ComboBox that accepts multiple inputs on a single line |
---|
| 12 | |
---|
| 13 | // delimiter: String |
---|
| 14 | // The character to use to separate items in the ComboBox input |
---|
| 15 | delimiter: ",", |
---|
| 16 | |
---|
| 17 | _previousMatches: false, |
---|
| 18 | |
---|
| 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 | |
---|
| 27 | _addPreviousMatches: function(/*String*/ text){ |
---|
| 28 | if(this._previousMatches){ |
---|
| 29 | if(!text.match(new RegExp("^"+this._previousMatches))){ |
---|
| 30 | text = this._previousMatches+text; |
---|
| 31 | } |
---|
| 32 | text = this._cleanupDelimiters(text); |
---|
| 33 | } |
---|
| 34 | return text; // String |
---|
| 35 | }, |
---|
| 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 | |
---|
| 46 | _autoCompleteText: function(/*String*/ text){ |
---|
| 47 | arguments[0] = this._addPreviousMatches(text); |
---|
| 48 | this.inherited(arguments); |
---|
| 49 | }, |
---|
| 50 | |
---|
| 51 | _startSearch: function(/*String*/ text){ |
---|
| 52 | text = this._cleanupDelimiters(text); |
---|
| 53 | var re = new RegExp("^.*"+this.delimiter+" *"); |
---|
| 54 | |
---|
| 55 | if((this._previousMatches = text.match(re))){ |
---|
| 56 | arguments[0] = text.replace(re, ""); |
---|
| 57 | } |
---|
| 58 | this.inherited(arguments); |
---|
| 59 | } |
---|
| 60 | }); |
---|
| 61 | }); |
---|