|  | @@ -1340,7 +1340,7 @@ the specific language governing permissions and limitations under the Apache Lic
 | 
											
												
													
														|  |                          if (self.opts.selectOnBlur) {
 |  |                          if (self.opts.selectOnBlur) {
 | 
											
												
													
														|  |                              self.selectHighlighted({noFocus: true});
 |  |                              self.selectHighlighted({noFocus: true});
 | 
											
												
													
														|  |                          }
 |  |                          }
 | 
											
												
													
														|  | -                        self.close({focus:true});
 |  | 
 | 
											
												
													
														|  | 
 |  | +                        self.close();
 | 
											
												
													
														|  |                          e.preventDefault();
 |  |                          e.preventDefault();
 | 
											
												
													
														|  |                          e.stopPropagation();
 |  |                          e.stopPropagation();
 | 
											
												
													
														|  |                      }
 |  |                      }
 | 
											
										
											
												
													
														|  | @@ -1927,14 +1927,13 @@ the specific language governing permissions and limitations under the Apache Lic
 | 
											
												
													
														|  |          },
 |  |          },
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |          // single
 |  |          // single
 | 
											
												
													
														|  | -        close: function (params) {
 |  | 
 | 
											
												
													
														|  | 
 |  | +        close: function () {
 | 
											
												
													
														|  |              if (!this.opened()) return;
 |  |              if (!this.opened()) return;
 | 
											
												
													
														|  |              this.parent.close.apply(this, arguments);
 |  |              this.parent.close.apply(this, arguments);
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -            params = params || {focus: true};
 |  | 
 | 
											
												
													
														|  |              this.focusser.prop("disabled", false);
 |  |              this.focusser.prop("disabled", false);
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -            if (params.focus) {
 |  | 
 | 
											
												
													
														|  | 
 |  | +            if (this.opts.shouldFocusInput(this)) {
 | 
											
												
													
														|  |                  this.focusser.focus();
 |  |                  this.focusser.focus();
 | 
											
												
													
														|  |              }
 |  |              }
 | 
											
												
													
														|  |          },
 |  |          },
 | 
											
										
											
												
													
														|  | @@ -1945,7 +1944,9 @@ the specific language governing permissions and limitations under the Apache Lic
 | 
											
												
													
														|  |                  this.close();
 |  |                  this.close();
 | 
											
												
													
														|  |              } else {
 |  |              } else {
 | 
											
												
													
														|  |                  this.focusser.prop("disabled", false);
 |  |                  this.focusser.prop("disabled", false);
 | 
											
												
													
														|  | -                this.focusser.focus();
 |  | 
 | 
											
												
													
														|  | 
 |  | +                if (this.opts.shouldFocusInput(this)) {
 | 
											
												
													
														|  | 
 |  | +                    this.focusser.focus();
 | 
											
												
													
														|  | 
 |  | +                }
 | 
											
												
													
														|  |              }
 |  |              }
 | 
											
												
													
														|  |          },
 |  |          },
 | 
											
												
													
														|  |  
 |  |  
 | 
											
										
											
												
													
														|  | @@ -1958,7 +1959,10 @@ the specific language governing permissions and limitations under the Apache Lic
 | 
											
												
													
														|  |          cancel: function () {
 |  |          cancel: function () {
 | 
											
												
													
														|  |              this.parent.cancel.apply(this, arguments);
 |  |              this.parent.cancel.apply(this, arguments);
 | 
											
												
													
														|  |              this.focusser.prop("disabled", false);
 |  |              this.focusser.prop("disabled", false);
 | 
											
												
													
														|  | -            this.focusser.focus();
 |  | 
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            if (this.opts.shouldFocusInput(this)) {
 | 
											
												
													
														|  | 
 |  | +                this.focusser.focus();
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  |          },
 |  |          },
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |          // single
 |  |          // single
 | 
											
										
											
												
													
														|  | @@ -2339,10 +2343,13 @@ the specific language governing permissions and limitations under the Apache Lic
 | 
											
												
													
														|  |              this.nextSearchTerm = this.opts.nextSearchTerm(data, this.search.val());
 |  |              this.nextSearchTerm = this.opts.nextSearchTerm(data, this.search.val());
 | 
											
												
													
														|  |              this.close();
 |  |              this.close();
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -            if (!options || !options.noFocus)
 |  | 
 | 
											
												
													
														|  | 
 |  | +            if ((!options || !options.noFocus) && this.opts.shouldFocusInput(this)) {
 | 
											
												
													
														|  |                  this.focusser.focus();
 |  |                  this.focusser.focus();
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -            if (!equal(old, this.id(data))) { this.triggerChange({added:data,removed:oldData}); }
 |  | 
 | 
											
												
													
														|  | 
 |  | +            if (!equal(old, this.id(data))) {
 | 
											
												
													
														|  | 
 |  | +                this.triggerChange({ added: data, removed: oldData });
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  |          },
 |  |          },
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |          // single
 |  |          // single
 | 
											
										
											
												
													
														|  | @@ -3347,7 +3354,15 @@ the specific language governing permissions and limitations under the Apache Lic
 | 
											
												
													
														|  |          nextSearchTerm: function(selectedObject, currentSearchTerm) { return undefined; },
 |  |          nextSearchTerm: function(selectedObject, currentSearchTerm) { return undefined; },
 | 
											
												
													
														|  |          hideSelectionFromResult: function(selectedObject) { return undefined; },
 |  |          hideSelectionFromResult: function(selectedObject) { return undefined; },
 | 
											
												
													
														|  |          searchInputPlaceholder: '',
 |  |          searchInputPlaceholder: '',
 | 
											
												
													
														|  | -        createSearchChoicePosition: 'top'
 |  | 
 | 
											
												
													
														|  | 
 |  | +        createSearchChoicePosition: 'top',
 | 
											
												
													
														|  | 
 |  | +        shouldFocusInput: function (instance) {
 | 
											
												
													
														|  | 
 |  | +            // Never focus the input if search is disabled
 | 
											
												
													
														|  | 
 |  | +            if (instance.opts.minimumResultsForSearch < 0) {
 | 
											
												
													
														|  | 
 |  | +                return false;
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            return true;
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  |      };
 |  |      };
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      $.fn.select2.ajaxDefaults = {
 |  |      $.fn.select2.ajaxDefaults = {
 |