Add support for disabled form fields.
This commit is contained in:
parent
91734e94ee
commit
f1e1c559ea
7 changed files with 136 additions and 69 deletions
|
@ -303,6 +303,15 @@
|
||||||
}
|
}
|
||||||
/* @end */
|
/* @end */
|
||||||
|
|
||||||
|
/* @group Disabled Support */
|
||||||
|
.chzn-disabled {
|
||||||
|
cursor: default;
|
||||||
|
opacity:0.5 !important;
|
||||||
|
}
|
||||||
|
.chzn-disabled .chzn-single {
|
||||||
|
cursor: default;
|
||||||
|
}
|
||||||
|
|
||||||
/* @group Right to Left */
|
/* @group Right to Left */
|
||||||
.chzn-rtl { direction:rtl;text-align: right; }
|
.chzn-rtl { direction:rtl;text-align: right; }
|
||||||
.chzn-rtl .chzn-single { padding-left: 0; padding-right: 8px; }
|
.chzn-rtl .chzn-single { padding-left: 0; padding-right: 8px; }
|
||||||
|
|
|
@ -44,6 +44,9 @@
|
||||||
this.click_test_action = __bind(function(evt) {
|
this.click_test_action = __bind(function(evt) {
|
||||||
return this.test_active_click(evt);
|
return this.test_active_click(evt);
|
||||||
}, this);
|
}, this);
|
||||||
|
this.activate_action = __bind(function(evt) {
|
||||||
|
return this.activate_field(evt);
|
||||||
|
}, this);
|
||||||
this.active_field = false;
|
this.active_field = false;
|
||||||
this.mouse_on_container = false;
|
this.mouse_on_container = false;
|
||||||
this.results_showing = false;
|
this.results_showing = false;
|
||||||
|
@ -134,13 +137,26 @@
|
||||||
return this.search_field.focus(__bind(function(evt) {
|
return this.search_field.focus(__bind(function(evt) {
|
||||||
return this.input_focus(evt);
|
return this.input_focus(evt);
|
||||||
}, this));
|
}, 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 {
|
} else {
|
||||||
return this.selected_item.focus(__bind(function(evt) {
|
this.container.removeClass('chzn-disabled');
|
||||||
return this.activate_field(evt);
|
this.search_field.attr('disabled', false);
|
||||||
}, this));
|
if (!this.is_multiple) {
|
||||||
|
return this.selected_item.bind("focus", this.activate_action);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Chosen.prototype.container_mousedown = function(evt) {
|
Chosen.prototype.container_mousedown = function(evt) {
|
||||||
|
if (!this.is_disabled) {
|
||||||
if (evt && evt.type === "mousedown") {
|
if (evt && evt.type === "mousedown") {
|
||||||
evt.stopPropagation();
|
evt.stopPropagation();
|
||||||
}
|
}
|
||||||
|
@ -159,6 +175,7 @@
|
||||||
} else {
|
} else {
|
||||||
return this.pending_destroy_click = false;
|
return this.pending_destroy_click = false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
Chosen.prototype.mouse_enter = function() {
|
Chosen.prototype.mouse_enter = function() {
|
||||||
return this.mouse_on_container = true;
|
return this.mouse_on_container = true;
|
||||||
|
@ -243,6 +260,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.search_field_disabled();
|
||||||
this.show_search_field_default();
|
this.show_search_field_default();
|
||||||
this.search_field_scale();
|
this.search_field_scale();
|
||||||
this.search_results.html(content);
|
this.search_results.html(content);
|
||||||
|
|
2
chosen/chosen.jquery.min.js
vendored
2
chosen/chosen.jquery.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -30,6 +30,9 @@
|
||||||
this.click_test_action = __bind(function(evt) {
|
this.click_test_action = __bind(function(evt) {
|
||||||
return this.test_active_click(evt);
|
return this.test_active_click(evt);
|
||||||
}, this);
|
}, this);
|
||||||
|
this.activate_action = __bind(function(evt) {
|
||||||
|
return this.activate_field(evt);
|
||||||
|
}, this);
|
||||||
this.active_field = false;
|
this.active_field = false;
|
||||||
this.mouse_on_container = false;
|
this.mouse_on_container = false;
|
||||||
this.results_showing = false;
|
this.results_showing = false;
|
||||||
|
@ -125,13 +128,26 @@
|
||||||
return this.search_field.observe("focus", __bind(function(evt) {
|
return this.search_field.observe("focus", __bind(function(evt) {
|
||||||
return this.input_focus(evt);
|
return this.input_focus(evt);
|
||||||
}, this));
|
}, 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 {
|
} else {
|
||||||
return this.selected_item.observe("focus", __bind(function(evt) {
|
this.container.removeClassName('chzn-disabled');
|
||||||
return this.activate_field(evt);
|
this.search_field.disabled = false;
|
||||||
}, this));
|
if (!this.is_multiple) {
|
||||||
|
return this.selected_item.observe("focus", this.activate_action);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Chosen.prototype.container_mousedown = function(evt) {
|
Chosen.prototype.container_mousedown = function(evt) {
|
||||||
|
if (!this.is_disabled) {
|
||||||
if (evt && evt.type === "mousedown") {
|
if (evt && evt.type === "mousedown") {
|
||||||
evt.stop();
|
evt.stop();
|
||||||
}
|
}
|
||||||
|
@ -149,6 +165,7 @@
|
||||||
} else {
|
} else {
|
||||||
return this.pending_destroy_click = false;
|
return this.pending_destroy_click = false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
Chosen.prototype.mouse_enter = function() {
|
Chosen.prototype.mouse_enter = function() {
|
||||||
return this.mouse_on_container = true;
|
return this.mouse_on_container = true;
|
||||||
|
@ -229,6 +246,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.search_field_disabled();
|
||||||
this.show_search_field_default();
|
this.show_search_field_default();
|
||||||
this.search_field_scale();
|
this.search_field_scale();
|
||||||
this.search_results.update(content);
|
this.search_results.update(content);
|
||||||
|
|
2
chosen/chosen.proto.min.js
vendored
2
chosen/chosen.proto.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -31,6 +31,7 @@ class Chosen
|
||||||
set_default_values: ->
|
set_default_values: ->
|
||||||
|
|
||||||
@click_test_action = (evt) => this.test_active_click(evt)
|
@click_test_action = (evt) => this.test_active_click(evt)
|
||||||
|
@activate_action = (evt) => this.activate_field(evt)
|
||||||
@active_field = false
|
@active_field = false
|
||||||
@mouse_on_container = false
|
@mouse_on_container = false
|
||||||
@results_showing = false
|
@results_showing = false
|
||||||
|
@ -105,10 +106,20 @@ class Chosen
|
||||||
if @is_multiple
|
if @is_multiple
|
||||||
@search_choices.click (evt) => this.choices_click(evt)
|
@search_choices.click (evt) => this.choices_click(evt)
|
||||||
@search_field.focus (evt) => this.input_focus(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
|
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) ->
|
container_mousedown: (evt) ->
|
||||||
|
if !@is_disabled
|
||||||
if evt and evt.type is "mousedown"
|
if evt and evt.type is "mousedown"
|
||||||
evt.stopPropagation()
|
evt.stopPropagation()
|
||||||
if not @pending_destroy_click
|
if not @pending_destroy_click
|
||||||
|
@ -195,6 +206,7 @@ class Chosen
|
||||||
else if data.selected and not @is_multiple
|
else if data.selected and not @is_multiple
|
||||||
@selected_item.find("span").text data.text
|
@selected_item.find("span").text data.text
|
||||||
|
|
||||||
|
this.search_field_disabled()
|
||||||
this.show_search_field_default()
|
this.show_search_field_default()
|
||||||
this.search_field_scale()
|
this.search_field_scale()
|
||||||
|
|
||||||
|
@ -552,7 +564,6 @@ class Chosen
|
||||||
this.keydown_arrow()
|
this.keydown_arrow()
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
search_field_scale: ->
|
search_field_scale: ->
|
||||||
if @is_multiple
|
if @is_multiple
|
||||||
h = 0
|
h = 0
|
||||||
|
|
|
@ -23,6 +23,7 @@ class Chosen
|
||||||
set_default_values: ->
|
set_default_values: ->
|
||||||
|
|
||||||
@click_test_action = (evt) => this.test_active_click(evt)
|
@click_test_action = (evt) => this.test_active_click(evt)
|
||||||
|
@activate_action = (evt) => this.activate_field(evt)
|
||||||
@active_field = false
|
@active_field = false
|
||||||
@mouse_on_container = false
|
@mouse_on_container = false
|
||||||
@results_showing = false
|
@results_showing = false
|
||||||
|
@ -100,11 +101,20 @@ class Chosen
|
||||||
if @is_multiple
|
if @is_multiple
|
||||||
@search_choices.observe "click", (evt) => this.choices_click(evt)
|
@search_choices.observe "click", (evt) => this.choices_click(evt)
|
||||||
@search_field.observe "focus", (evt) => this.input_focus(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) ->
|
container_mousedown: (evt) ->
|
||||||
|
if !@is_disabled
|
||||||
if evt and evt.type is "mousedown"
|
if evt and evt.type is "mousedown"
|
||||||
evt.stop()
|
evt.stop()
|
||||||
if not @pending_destroy_click
|
if not @pending_destroy_click
|
||||||
|
@ -190,6 +200,7 @@ class Chosen
|
||||||
else if data.selected and not @is_multiple
|
else if data.selected and not @is_multiple
|
||||||
@selected_item.down("span").update( data.html )
|
@selected_item.down("span").update( data.html )
|
||||||
|
|
||||||
|
this.search_field_disabled()
|
||||||
this.show_search_field_default()
|
this.show_search_field_default()
|
||||||
this.search_field_scale()
|
this.search_field_scale()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue