Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prevent activating disabled fields #2721

Merged
merged 1 commit into from
Oct 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions coffee/chosen.jquery.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,21 @@ class Chosen extends AbstractChosen
@selected_item.bind "focus.chosen", @activate_action if !@is_multiple

container_mousedown: (evt) ->
if !@is_disabled
if evt and evt.type is "mousedown" and not @results_showing
evt.preventDefault()
return if @is_disabled

if not (evt? and ($ evt.target).hasClass "search-choice-close")
if not @active_field
@search_field.val "" if @is_multiple
$(@container[0].ownerDocument).bind 'click.chosen', @click_test_action
this.results_show()
else if not @is_multiple and evt and (($(evt.target)[0] == @selected_item[0]) || $(evt.target).parents("a.chosen-single").length)
evt.preventDefault()
this.results_toggle()
if evt and evt.type is "mousedown" and not @results_showing
evt.preventDefault()

this.activate_field()
if not (evt? and ($ evt.target).hasClass "search-choice-close")
if not @active_field
@search_field.val "" if @is_multiple
$(@container[0].ownerDocument).bind 'click.chosen', @click_test_action
this.results_show()
else if not @is_multiple and evt and (($(evt.target)[0] == @selected_item[0]) || $(evt.target).parents("a.chosen-single").length)
evt.preventDefault()
this.results_toggle()

this.activate_field()

container_mouseup: (evt) ->
this.results_reset(evt) if evt.target.nodeName is "ABBR" and not @is_disabled
Expand Down Expand Up @@ -168,6 +169,8 @@ class Chosen extends AbstractChosen
this.search_field_scale()

activate_field: ->
return if @is_disabled

@container.addClass "chosen-container-active"
@active_field = true

Expand Down Expand Up @@ -269,7 +272,7 @@ class Chosen extends AbstractChosen
@form_field_label = $("label[for='#{@form_field.id}']") #next check for a for=#{id}

if @form_field_label.length > 0
@form_field_label.bind 'click.chosen', (evt) => if @is_multiple then this.container_mousedown(evt) else this.activate_field()
@form_field_label.bind 'click.chosen', this.label_click_handler

show_search_field_default: ->
if @is_multiple and this.choices_count() < 1 and not @active_field
Expand Down
27 changes: 15 additions & 12 deletions coffee/chosen.proto.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,20 @@ class @Chosen extends AbstractChosen
@selected_item.observe "focus", @activate_action if !@is_multiple

container_mousedown: (evt) ->
if !@is_disabled
if evt and evt.type is "mousedown" and not @results_showing
evt.stop()
return if @is_disabled

if not (evt? and evt.target.hasClassName "search-choice-close")
if not @active_field
@search_field.clear() if @is_multiple
@container.ownerDocument.observe "click", @click_test_action
this.results_show()
else if not @is_multiple and evt and (evt.target is @selected_item || evt.target.up("a.chosen-single"))
this.results_toggle()
if evt and evt.type is "mousedown" and not @results_showing
evt.stop()

this.activate_field()
if not (evt? and evt.target.hasClassName "search-choice-close")
if not @active_field
@search_field.clear() if @is_multiple
@container.ownerDocument.observe "click", @click_test_action
this.results_show()
else if not @is_multiple and evt and (evt.target is @selected_item || evt.target.up("a.chosen-single"))
this.results_toggle()

this.activate_field()

container_mouseup: (evt) ->
this.results_reset(evt) if evt.target.nodeName is "ABBR" and not @is_disabled
Expand Down Expand Up @@ -162,6 +163,8 @@ class @Chosen extends AbstractChosen
this.search_field_scale()

activate_field: ->
return if @is_disabled

@container.addClassName "chosen-container-active"
@active_field = true

Expand Down Expand Up @@ -260,7 +263,7 @@ class @Chosen extends AbstractChosen
@form_field_label = $$("label[for='#{@form_field.id}']").first() #next check for a for=#{id}

if @form_field_label?
@form_field_label.observe "click", (evt) => if @is_multiple then this.container_mousedown(evt) else this.activate_field()
@form_field_label.observe "click", this.label_click_handler

show_search_field_default: ->
if @is_multiple and this.choices_count() < 1 and not @active_field
Expand Down
6 changes: 6 additions & 0 deletions coffee/lib/abstract-chosen.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ class AbstractChosen
@active_field = false
setTimeout (=> this.blur_test()), 100

label_click_handler: (evt) =>
if @is_multiple
this.container_mousedown(evt)
else
this.activate_field()

results_option_build: (options) ->
content = ''
shown_results = 0
Expand Down