Add support for disabled form fields.

This commit is contained in:
Patrick Filler 2011-09-22 12:44:00 -05:00
parent 91734e94ee
commit f1e1c559ea
7 changed files with 136 additions and 69 deletions

View file

@ -303,6 +303,15 @@
}
/* @end */
/* @group Disabled Support */
.chzn-disabled {
cursor: default;
opacity:0.5 !important;
}
.chzn-disabled .chzn-single {
cursor: default;
}
/* @group Right to Left */
.chzn-rtl { direction:rtl;text-align: right; }
.chzn-rtl .chzn-single { padding-left: 0; padding-right: 8px; }

View file

@ -44,6 +44,9 @@
this.click_test_action = __bind(function(evt) {
return this.test_active_click(evt);
}, this);
this.activate_action = __bind(function(evt) {
return this.activate_field(evt);
}, this);
this.active_field = false;
this.mouse_on_container = false;
this.results_showing = false;
@ -134,13 +137,26 @@
return this.search_field.focus(__bind(function(evt) {
return this.input_focus(evt);
}, this));
}
};
Chosen.prototype.search_field_disabled = function() {
this.is_disabled = this.form_field_jq.attr('disabled');
if (this.is_disabled) {
this.container.addClass('chzn-disabled');
this.search_field.attr('disabled', true);
if (!this.is_multiple) {
return this.selected_item.unbind("focus", this.activate_action);
}
} else {
return this.selected_item.focus(__bind(function(evt) {
return this.activate_field(evt);
}, this));
this.container.removeClass('chzn-disabled');
this.search_field.attr('disabled', false);
if (!this.is_multiple) {
return this.selected_item.bind("focus", this.activate_action);
}
}
};
Chosen.prototype.container_mousedown = function(evt) {
if (!this.is_disabled) {
if (evt && evt.type === "mousedown") {
evt.stopPropagation();
}
@ -159,6 +175,7 @@
} else {
return this.pending_destroy_click = false;
}
}
};
Chosen.prototype.mouse_enter = function() {
return this.mouse_on_container = true;
@ -243,6 +260,7 @@
}
}
}
this.search_field_disabled();
this.show_search_field_default();
this.search_field_scale();
this.search_results.html(content);

File diff suppressed because one or more lines are too long

View file

@ -30,6 +30,9 @@
this.click_test_action = __bind(function(evt) {
return this.test_active_click(evt);
}, this);
this.activate_action = __bind(function(evt) {
return this.activate_field(evt);
}, this);
this.active_field = false;
this.mouse_on_container = false;
this.results_showing = false;
@ -125,13 +128,26 @@
return this.search_field.observe("focus", __bind(function(evt) {
return this.input_focus(evt);
}, this));
}
};
Chosen.prototype.search_field_disabled = function() {
this.is_disabled = this.form_field.disabled;
if (this.is_disabled) {
this.container.addClassName('chzn-disabled');
this.search_field.disabled = true;
if (!this.is_multiple) {
return this.selected_item.stopObserving("focus", this.activate_action);
}
} else {
return this.selected_item.observe("focus", __bind(function(evt) {
return this.activate_field(evt);
}, this));
this.container.removeClassName('chzn-disabled');
this.search_field.disabled = false;
if (!this.is_multiple) {
return this.selected_item.observe("focus", this.activate_action);
}
}
};
Chosen.prototype.container_mousedown = function(evt) {
if (!this.is_disabled) {
if (evt && evt.type === "mousedown") {
evt.stop();
}
@ -149,6 +165,7 @@
} else {
return this.pending_destroy_click = false;
}
}
};
Chosen.prototype.mouse_enter = function() {
return this.mouse_on_container = true;
@ -229,6 +246,7 @@
}
}
}
this.search_field_disabled();
this.show_search_field_default();
this.search_field_scale();
this.search_results.update(content);

File diff suppressed because one or more lines are too long

View file

@ -31,6 +31,7 @@ class Chosen
set_default_values: ->
@click_test_action = (evt) => this.test_active_click(evt)
@activate_action = (evt) => this.activate_field(evt)
@active_field = false
@mouse_on_container = false
@results_showing = false
@ -105,10 +106,20 @@ class Chosen
if @is_multiple
@search_choices.click (evt) => this.choices_click(evt)
@search_field.focus (evt) => this.input_focus(evt)
search_field_disabled: ->
@is_disabled = @form_field_jq.attr 'disabled'
if(@is_disabled)
@container.addClass 'chzn-disabled'
@search_field.attr 'disabled', true
@selected_item.unbind "focus", @activate_action if !@is_multiple
else
@selected_item.focus (evt) => this.activate_field(evt)
@container.removeClass 'chzn-disabled'
@search_field.attr 'disabled', false
@selected_item.bind "focus", @activate_action if !@is_multiple
container_mousedown: (evt) ->
if !@is_disabled
if evt and evt.type is "mousedown"
evt.stopPropagation()
if not @pending_destroy_click
@ -195,6 +206,7 @@ class Chosen
else if data.selected and not @is_multiple
@selected_item.find("span").text data.text
this.search_field_disabled()
this.show_search_field_default()
this.search_field_scale()
@ -552,7 +564,6 @@ class Chosen
this.keydown_arrow()
break
search_field_scale: ->
if @is_multiple
h = 0

View file

@ -23,6 +23,7 @@ class Chosen
set_default_values: ->
@click_test_action = (evt) => this.test_active_click(evt)
@activate_action = (evt) => this.activate_field(evt)
@active_field = false
@mouse_on_container = false
@results_showing = false
@ -100,11 +101,20 @@ class Chosen
if @is_multiple
@search_choices.observe "click", (evt) => this.choices_click(evt)
@search_field.observe "focus", (evt) => this.input_focus(evt)
else
@selected_item.observe "focus", (evt) => this.activate_field(evt)
search_field_disabled: ->
@is_disabled = @form_field.disabled
if(@is_disabled)
@container.addClassName 'chzn-disabled'
@search_field.disabled = true
@selected_item.stopObserving "focus", @activate_action if !@is_multiple
else
@container.removeClassName 'chzn-disabled'
@search_field.disabled = false
@selected_item.observe "focus", @activate_action if !@is_multiple
container_mousedown: (evt) ->
if !@is_disabled
if evt and evt.type is "mousedown"
evt.stop()
if not @pending_destroy_click
@ -190,6 +200,7 @@ class Chosen
else if data.selected and not @is_multiple
@selected_item.down("span").update( data.html )
this.search_field_disabled()
this.show_search_field_default()
this.search_field_scale()