source: Dev/branches/rest-dojo-ui/client/dojox/form/MultiComboBox.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 1.7 KB
Line 
1define([
2        "dojo/_base/kernel",
3        "dijit/form/ValidationTextBox",
4        "dijit/form/ComboBoxMixin",
5        "dojo/_base/declare"
6], function(kernel, ValidationTextBox, ComboBoxMixin, declare){
7kernel.experimental("dojox.form.MultiComboBox");
8
9        /*=====
10                ValidationTextBox = dijit.form.ValidationTextBox;
11                ComboBoxMixin = dijit.form.ComboBoxMixin;
12        =====*/
13return declare("dojox.form.MultiComboBox", [ValidationTextBox, ComboBoxMixin],{
14        // summary:
15        //              A ComboBox that accepts 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
21        _previousMatches: false,
22
23        _setValueAttr: function(value){
24                if(this.delimiter && value.length != 0){
25                        value = value+this.delimiter+" ";
26                        arguments[0] = this._addPreviousMatches(value);
27                }
28                this.inherited(arguments);
29        },
30
31        _addPreviousMatches: function(/* String */text){
32                if(this._previousMatches){
33                        if(!text.match(new RegExp("^"+this._previousMatches))){
34                                text = this._previousMatches+text;
35                        }
36                        text = this._cleanupDelimiters(text);
37                }
38                return text; // String
39        },
40
41        _cleanupDelimiters: function(/* String */text){
42                if(this.delimiter){
43                        text = text.replace(new RegExp("  +"), " ");
44                        text = text.replace(new RegExp("^ *"+this.delimiter+"* *"), "");
45                        text = text.replace(new RegExp(this.delimiter+" *"+this.delimiter), this.delimiter);
46                }
47                return text;
48        },
49
50        _autoCompleteText: function(/* String */text){
51                arguments[0] = this._addPreviousMatches(text);
52                this.inherited(arguments);
53        },
54
55        _startSearch: function(/* String */text){
56                text = this._cleanupDelimiters(text);
57                var re = new RegExp("^.*"+this.delimiter+" *");
58
59                if((this._previousMatches = text.match(re))){
60                        arguments[0] = text.replace(re, "");
61                }
62                this.inherited(arguments);
63        }
64});
65});
Note: See TracBrowser for help on using the repository browser.