Permalink
Browse files

Fixes tab order issues with single Chosen.

  • Loading branch information...
1 parent 3640fa1 commit 9085750ecd023d7a2a7c48c20ab70cc0309635b6 @pfiller pfiller committed Oct 9, 2012
View
@@ -157,10 +157,14 @@ Copyright (c) 2011 by Harvest
AbstractChosen.prototype.input_focus = function(evt) {
var _this = this;
- if (!this.active_field) {
- return setTimeout((function() {
- return _this.container_mousedown();
- }), 50);
+ if (this.is_multiple) {
+ if (!this.active_field) {
+ return setTimeout((function() {
+ return _this.container_mousedown();
+ }), 50);
+ }
+ } else {
+ if (!this.active_field) return this.activate_field();
}
};
@@ -401,13 +405,13 @@ Copyright (c) 2011 by Harvest
this.search_field.keydown(function(evt) {
return _this.keydown_checker(evt);
});
+ this.search_field.focus(function(evt) {
+ return _this.input_focus(evt);
+ });
if (this.is_multiple) {
- this.search_choices.click(function(evt) {
+ return this.search_choices.click(function(evt) {
return _this.choices_click(evt);
});
- return this.search_field.focus(function(evt) {
- return _this.input_focus(evt);
- });
} else {
return this.container.click(function(evt) {
return evt.preventDefault();
@@ -470,10 +474,6 @@ Copyright (c) 2011 by Harvest
Chosen.prototype.close_field = function() {
$(document).unbind("click", this.click_test_action);
- if (!this.is_multiple) {
- this.selected_item.attr("tabindex", this.search_field.attr("tabindex"));
- this.search_field.attr("tabindex", -1);
- }
this.active_field = false;
this.results_hide();
this.container.removeClass("chzn-container-active");
@@ -484,10 +484,6 @@ Copyright (c) 2011 by Harvest
};
Chosen.prototype.activate_field = function() {
- if (!this.is_multiple && !this.active_field) {
- this.search_field.attr("tabindex", this.selected_item.attr("tabindex"));
- this.selected_item.attr("tabindex", -1);
- }
this.container.addClass("chzn-container-active");
this.active_field = true;
this.search_field.val(this.search_field.val());
@@ -619,12 +615,7 @@ Copyright (c) 2011 by Harvest
if (this.form_field_jq.attr("tabindex")) {
ti = this.form_field_jq.attr("tabindex");
this.form_field_jq.attr("tabindex", -1);
- if (this.is_multiple) {
- return this.search_field.attr("tabindex", ti);
- } else {
- this.selected_item.attr("tabindex", ti);
- return this.search_field.attr("tabindex", -1);
- }
+ return this.search_field.attr("tabindex", ti);
}
};
@@ -643,7 +634,8 @@ Copyright (c) 2011 by Harvest
target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
if (target.length) {
this.result_highlight = target;
- return this.result_select(evt);
+ this.result_select(evt);
+ return this.search_field.focus();
}
};

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -157,10 +157,14 @@ Copyright (c) 2011 by Harvest
AbstractChosen.prototype.input_focus = function(evt) {
var _this = this;
- if (!this.active_field) {
- return setTimeout((function() {
- return _this.container_mousedown();
- }), 50);
+ if (this.is_multiple) {
+ if (!this.active_field) {
+ return setTimeout((function() {
+ return _this.container_mousedown();
+ }), 50);
+ }
+ } else {
+ if (!this.active_field) return this.activate_field();
}
};
@@ -393,13 +397,13 @@ Copyright (c) 2011 by Harvest
this.search_field.observe("keydown", function(evt) {
return _this.keydown_checker(evt);
});
+ this.search_field.observe("focus", function(evt) {
+ return _this.input_focus(evt);
+ });
if (this.is_multiple) {
- this.search_choices.observe("click", function(evt) {
+ return this.search_choices.observe("click", function(evt) {
return _this.choices_click(evt);
});
- return this.search_field.observe("focus", function(evt) {
- return _this.input_focus(evt);
- });
} else {
return this.container.observe("click", function(evt) {
return evt.preventDefault();
@@ -459,10 +463,6 @@ Copyright (c) 2011 by Harvest
Chosen.prototype.close_field = function() {
document.stopObserving("click", this.click_test_action);
- if (!this.is_multiple) {
- this.selected_item.tabIndex = this.search_field.tabIndex;
- this.search_field.tabIndex = -1;
- }
this.active_field = false;
this.results_hide();
this.container.removeClassName("chzn-container-active");
@@ -473,10 +473,6 @@ Copyright (c) 2011 by Harvest
};
Chosen.prototype.activate_field = function() {
- if (!this.is_multiple && !this.active_field) {
- this.search_field.tabIndex = this.selected_item.tabIndex;
- this.selected_item.tabIndex = -1;
- }
this.container.addClassName("chzn-container-active");
this.active_field = true;
this.search_field.value = this.search_field.value;
@@ -608,12 +604,7 @@ Copyright (c) 2011 by Harvest
if (this.form_field.tabIndex) {
ti = this.form_field.tabIndex;
this.form_field.tabIndex = -1;
- if (this.is_multiple) {
- return this.search_field.tabIndex = ti;
- } else {
- this.selected_item.tabIndex = ti;
- return this.search_field.tabIndex = -1;
- }
+ return this.search_field.tabIndex = ti;
}
};
@@ -632,7 +623,8 @@ Copyright (c) 2011 by Harvest
target = evt.target.hasClassName("active-result") ? evt.target : evt.target.up(".active-result");
if (target) {
this.result_highlight = target;
- return this.result_select(evt);
+ this.result_select(evt);
+ return this.search_field.focus();
}
};

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -89,12 +89,13 @@ class Chosen extends AbstractChosen
@search_field.blur (evt) => this.input_blur(evt)
@search_field.keyup (evt) => this.keyup_checker(evt)
@search_field.keydown (evt) => this.keydown_checker(evt)
+ @search_field.focus (evt) => this.input_focus(evt)
if @is_multiple
@search_choices.click (evt) => this.choices_click(evt)
- @search_field.focus (evt) => this.input_focus(evt)
else
@container.click (evt) => evt.preventDefault() # gobble click of anchor
+
search_field_disabled: ->
@is_disabled = @form_field_jq[0].disabled
@@ -135,10 +136,6 @@ class Chosen extends AbstractChosen
close_field: ->
$(document).unbind "click", @click_test_action
- if not @is_multiple
- @selected_item.attr "tabindex", @search_field.attr("tabindex")
- @search_field.attr "tabindex", -1
-
@active_field = false
this.results_hide()
@@ -150,10 +147,6 @@ class Chosen extends AbstractChosen
this.search_field_scale()
activate_field: ->
- if not @is_multiple and not @active_field
- @search_field.attr "tabindex", (@selected_item.attr "tabindex")
- @selected_item.attr "tabindex", -1
-
@container.addClass "chzn-container-active"
@active_field = true
@@ -262,12 +255,7 @@ class Chosen extends AbstractChosen
if @form_field_jq.attr "tabindex"
ti = @form_field_jq.attr "tabindex"
@form_field_jq.attr "tabindex", -1
-
- if @is_multiple
- @search_field.attr "tabindex", ti
- else
- @selected_item.attr "tabindex", ti
- @search_field.attr "tabindex", -1
+ @search_field.attr "tabindex", ti
show_search_field_default: ->
if @is_multiple and @choices < 1 and not @active_field
@@ -282,6 +270,7 @@ class Chosen extends AbstractChosen
if target.length
@result_highlight = target
this.result_select(evt)
+ @search_field.focus()
search_results_mouseover: (evt) ->
target = if $(evt.target).hasClass "active-result" then $(evt.target) else $(evt.target).parents(".active-result").first()
View
@@ -81,10 +81,10 @@ class Chosen extends AbstractChosen
@search_field.observe "blur", (evt) => this.input_blur(evt)
@search_field.observe "keyup", (evt) => this.keyup_checker(evt)
@search_field.observe "keydown", (evt) => this.keydown_checker(evt)
+ @search_field.observe "focus", (evt) => this.input_focus(evt)
if @is_multiple
@search_choices.observe "click", (evt) => this.choices_click(evt)
- @search_field.observe "focus", (evt) => this.input_focus(evt)
else
@container.observe "click", (evt) => evt.preventDefault() # gobble click of anchor
@@ -126,10 +126,6 @@ class Chosen extends AbstractChosen
close_field: ->
document.stopObserving "click", @click_test_action
- if not @is_multiple
- @selected_item.tabIndex = @search_field.tabIndex
- @search_field.tabIndex = -1
-
@active_field = false
this.results_hide()
@@ -141,17 +137,12 @@ class Chosen extends AbstractChosen
this.search_field_scale()
activate_field: ->
- if not @is_multiple and not @active_field
- @search_field.tabIndex = @selected_item.tabIndex
- @selected_item.tabIndex = -1
-
@container.addClassName "chzn-container-active"
@active_field = true
@search_field.value = @search_field.value
@search_field.focus()
-
test_active_click: (evt) ->
if evt.target.up('#' + @container_id)
@active_field = true
@@ -252,12 +243,7 @@ class Chosen extends AbstractChosen
if @form_field.tabIndex
ti = @form_field.tabIndex
@form_field.tabIndex = -1
-
- if @is_multiple
- @search_field.tabIndex = ti
- else
- @selected_item.tabIndex = ti
- @search_field.tabIndex = -1
+ @search_field.tabIndex = ti
show_search_field_default: ->
if @is_multiple and @choices < 1 and not @active_field
@@ -272,6 +258,7 @@ class Chosen extends AbstractChosen
if target
@result_highlight = target
this.result_select(evt)
+ @search_field.focus()
search_results_mouseover: (evt) ->
target = if evt.target.hasClassName("active-result") then evt.target else evt.target.up(".active-result")
@@ -49,7 +49,10 @@ class AbstractChosen
mouse_leave: -> @mouse_on_container = false
input_focus: (evt) ->
- setTimeout (=> this.container_mousedown()), 50 unless @active_field
+ if @is_multiple
+ setTimeout (=> this.container_mousedown()), 50 unless @active_field
+ else
+ @activate_field() unless @active_field
input_blur: (evt) ->
if not @mouse_on_container

0 comments on commit 9085750

Please sign in to comment.