Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

combobox change: when the buttons are hidden, just changing the selec…

…tion saves the change

 + previously you had to hit enter, this brings it into line with user expectations
  • Loading branch information...
commit f0e518cf9d2eb4b8bd7ead80c495c55b070de33f 1 parent 0db18bd
@reednj authored
Showing with 43 additions and 31 deletions.
  1. +42 −30 Source/InlineEditor.Combo.js
  2. +1 −1  Test/simpletest.html
View
72 Source/InlineEditor.Combo.js
@@ -17,7 +17,7 @@ provides: InlineEditor.Combo
*/
InlineEditor.Combo = new Class({
Extends: InlineEditor,
-
+
initialize: function(elem, options) {
this.element = $(elem);
this.options = options || {};
@@ -25,50 +25,59 @@ InlineEditor.Combo = new Class({
this.options.selected = this.options.selected || this.element.get('data-selected');
this.parent(this.element, this.options);
-
+
this.selectedIndex = this._set_default(this.options.options_list);
this.edit_link.innerHTML = this.current_text;
},
-
+
+ _selection_changed: function() {
+
+ if(this.options.hide_buttons) {
+ // if the buttons are hidden, then we just submit straight away, no
+ // waiting for the user to press enter
+ this.save_edit();
+ }
+ },
+
// if they have specified their option list in the dom
// then read it in and put in a standard format
_read_options: function() {
var options_list = [];
var div_list = this.element.getElements('div');
-
+
if(div_list == null || div_list.length == 0) {
return;
}
-
+
div_list.each(function(item) {
// the attributes here will be passed straight to the create element
// function, so they must be valud html attrs.
var new_item = {'value':item.get('data-value'), 'text':item.innerHTML};
-
+
// is this the default item? do some special things in that case
if(item.get('data-selected') == 'true') {
new_item.selected = true;
}
-
+
options_list.push(new_item);
}.bind(this));
-
+
return options_list;
},
-
+
_set_default: function(options_list) {
var has_default = false;
var selectedIndex = -1;
-
+
// has the user set the selected item on the root node itself?
if($defined(this.options.selected)) {
this.edit_input.value = this.options.selected;
this.current_text = this.edit_input.options[this.edit_input.selectedIndex].text;
return this.edit_input.selectedIndex;
}
-
+
// scan through the list, set the current_text, and select the
- // default item. if no default is specified then select the top
+ // default item. if no default is specified then select the top
// item.
for(var i=0; i < options_list.length; i++) {
if(options_list[i].selected == true) {
@@ -78,43 +87,46 @@ InlineEditor.Combo = new Class({
break;
}
}
-
+
if(has_default == false && options_list.length > 0) {
this.current_text = options_list[0].text;
selectedIndex = 0;
}
-
+
return selectedIndex;
},
-
+
_create_input: function() {
// conver the options list too a bunch of proper options elements
var option_elems = [];
this.options.options_list.each(function(item) {
option_elems.push($e('option', item));
});
-
+
return $e('select', {
'children': option_elems,
- 'events': {'keydown': function(e) {
- // detect the escape key, and use it to cancel the edit
- // this event code is duplicated between ie & ie.combo.
- // it should really be moved somewhere common...
- if(e.key == 'esc') {
- this.cancel_edit();
- } else if(e.key == 'enter') {
- // we have to capture this for the select box
- // for some reason the form does not detect it properly
- this.save_edit();
- }
- }.bind(this)}});
+ 'events': {
+ 'keydown': function(e) {
+ // detect the escape key, and use it to cancel the edit
+ // this event code is duplicated between ie & ie.combo.
+ // it should really be moved somewhere common...
+ if(e.key == 'esc') {
+ this.cancel_edit();
+ } else if(e.key == 'enter') {
+ // we have to capture this for the select box
+ // for some reason the form does not detect it properly
+ this.save_edit();
+ }
+ }.bind(this),
+ 'change': this._selection_changed.bind(this)
+ }});
},
-
+
_set_link: function() {
this.selectedIndex = this.edit_input.selectedIndex;
this.current_text = this.edit_input.options[this.selectedIndex].text;
this.edit_link.innerHTML = this.current_text;
-
+
this.options.onSuccess(this.current_text, this.edit_input.value);
}
});
View
2  Test/simpletest.html
@@ -34,7 +34,7 @@
});
$$('.editable-dd').each(function(item) {
- new InlineEditor.Combo(item);
+ new InlineEditor.Combo(item, {hide_buttons: true});
});
new InlineEditor.Combo('edit-combo', {
Please sign in to comment.
Something went wrong with that request. Please try again.