|
20 | 20 | valueProperty: null,
|
21 | 21 | itemsPerPage: 10,
|
22 | 22 | dropdownWidth: null,
|
23 |
| - elementType: 'text', |
| 23 | + elementType: "text", |
24 | 24 | persistState: false,
|
25 | 25 | closeBtnRequired: true,
|
26 | 26 | footerRequired: true,
|
|
111 | 111 | var self = this,
|
112 | 112 | el = self.element;
|
113 | 113 |
|
114 |
| - if(self.options.elementType && self.options.elementType == 'text') { |
| 114 | + if(self.options.elementType && self.options.elementType == "text") { |
115 | 115 | el.keydown(function( event ) {
|
116 | 116 | self._keyNavigations( event );
|
117 | 117 | });
|
|
138 | 138 | self._fetchData( $.trim(el.val()) );
|
139 | 139 | });
|
140 | 140 | }
|
141 |
| - else if(self.options.elementType && self.options.elementType == 'link') { |
| 141 | + else if(self.options.elementType && self.options.elementType == "link") { |
142 | 142 | el.click(function( event ) {
|
143 | 143 | self._fetchData();
|
144 | 144 | });
|
|
169 | 169 | var el = this.element;
|
170 | 170 | if(this.options.valueProperty) {
|
171 | 171 | if($.type(o) == "object") {
|
172 |
| - el.val( o[this.options.valueProperty] ).focus(); |
| 172 | + el.val( $.type(this.options.valueProperty) == "array" ? o[this.options.valueProperty[0]] : o[this.options.valueProperty] ).focus(); |
173 | 173 | }
|
174 | 174 | else {
|
175 | 175 | el.val( o ).focus();
|
|
290 | 290 | this._bindDropdownComponentEvents();
|
291 | 291 | this._highlightItem(this._getWidgetState().highlightedIndex);
|
292 | 292 | this._markAllItems();
|
| 293 | + this.element.parent().find( "." + this.wp.widgetBaseClass + this.wp.hyphen + this.wp.containerLabel ).show(); |
293 | 294 | },
|
294 | 295 | _constructHtmlUsingTemplate: function() {
|
295 | 296 | var self = this,
|
|
298 | 299 | widgetState = self._getWidgetState(),
|
299 | 300 | matchedText = null,
|
300 | 301 | underlinedText = null,
|
301 |
| - highlightRegExp = new RegExp(widgetState.query, "i"), |
| 302 | + highlightRegExp = new RegExp($.ui.autocomplete.escapeRegex(widgetState.query), "i"), |
302 | 303 | highlightQueryText = function(text) {
|
303 | 304 | underlinedText = "";
|
304 | 305 | matchedText = text.match(highlightRegExp);
|
|
323 | 324 | if($.type(item) == "object") {
|
324 | 325 | $.each(item, function(k, v) {
|
325 | 326 | var templateKey = "{@:" + k + "}",
|
326 |
| - regEx = new RegExp(templateKey, "g"); |
| 327 | + regEx = new RegExp($.ui.autocomplete.escapeRegex(templateKey), "g"); |
327 | 328 |
|
328 | 329 | if(self.options.itemTemplate.indexOf( templateKey ) != -1) {
|
329 |
| - templateClone = templateClone.replace( regEx, (k == self.options.valueProperty) ? highlightQueryText(v) : v ); |
| 330 | + if($.type(self.options.valueProperty) == "array") { |
| 331 | + templateClone = templateClone.replace( regEx, (self.options.valueProperty.indexOf(k) != -1) ? highlightQueryText(v) : v ); |
| 332 | + } |
| 333 | + else { |
| 334 | + templateClone = templateClone.replace( regEx, (k == self.options.valueProperty) ? highlightQueryText(v) : v ); |
| 335 | + } |
330 | 336 | }
|
331 | 337 | });
|
332 | 338 | }
|
333 | 339 | else {
|
334 | 340 | var templateKey = "{@:" + self.options.valueProperty + "}",
|
335 |
| - regEx = new RegExp(templateKey, "g"); |
| 341 | + regEx = new RegExp($.ui.autocomplete.escapeRegex(templateKey), "g"); |
336 | 342 |
|
337 | 343 | if(self.options.itemTemplate.indexOf( templateKey ) != -1) {
|
338 | 344 | templateClone = templateClone.replace( regEx, (k == self.options.valueProperty) ? highlightQueryText(item) : item );
|
|
427 | 433 | parent = self.element.parent();
|
428 | 434 | // bind footer events only if footer is required.
|
429 | 435 | if(self.options.footerRequired) {
|
| 436 | + // TODO: If customisable footer is provided, then we should be able to specify elements to attach events too, |
| 437 | + // rather than creating a generic CSS definition to attach the events to. |
430 | 438 | parent.find( "." + self.wp.widgetBaseClass + self.wp.hyphen + self.wp.footerLabel ).bind("click dblclick", function( e ) {
|
431 | 439 | self.element.focus();
|
432 | 440 | });
|
|
466 | 474 | },
|
467 | 475 | _markAllItems: function() {
|
468 | 476 | var self = this,
|
469 |
| - items = this.element.siblings( "." + this.wp.widgetBaseClass + this.wp.hyphen + this.wp.containerLabel ).children(); |
| 477 | + items = this.element.siblings( "." + this.wp.widgetBaseClass + this.wp.hyphen + this.wp.containerLabel ).children().not( "." + this.wp.widgetBaseClass + this.wp.hyphen + this.wp.footerLabel ); |
470 | 478 | items.each(function(index, item) {
|
471 |
| - if(!$( item ).hasClass( self.wp.widgetBaseClass + self.wp.hyphen + self.wp.footerLabel )) { |
472 |
| - $( item ).addClass( self.wp.widgetBaseClass + self.wp.hyphen + self.wp.itemLabel ); |
473 |
| - } |
| 479 | + $( item ).addClass( self.wp.widgetBaseClass + self.wp.hyphen + self.wp.itemLabel ); |
474 | 480 | });
|
475 | 481 | },
|
476 | 482 | _removeItemHighlight: function(selectedItem) {
|
|
0 commit comments