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
7 changes: 5 additions & 2 deletions coffee/chosen.jquery.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ class Chosen extends AbstractChosen
@selected_item.bind "focus.chosen", @activate_action if !@is_multiple

container_mousedown: (evt) ->
if !@is_disabled
return if @is_disabled

if evt and evt.type is "mousedown" and not @results_showing
evt.preventDefault()

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
7 changes: 5 additions & 2 deletions coffee/chosen.proto.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ class @Chosen extends AbstractChosen
@selected_item.observe "focus", @activate_action if !@is_multiple

container_mousedown: (evt) ->
if !@is_disabled
return if @is_disabled

if evt and evt.type is "mousedown" and not @results_showing
evt.stop()

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