Permalink
Browse files

added 'selected' option to set the current item of a dropdown on the …

…root node (instead of on the list itself)
  • Loading branch information...
1 parent 10f60af commit 10134ba6e547f813ec5df6df8f224990849ca3c7 @reednj committed Sep 7, 2010
Showing with 12 additions and 3 deletions.
  1. +1 −0 Docs/InlineEditor.Combo.md
  2. +1 −1 README.md
  3. +9 −1 Source/InlineEditor.Combo.js
  4. +1 −1 Test/simpletest.html
View
1 Docs/InlineEditor.Combo.md
@@ -19,6 +19,7 @@ InlineEditor Method: constructor {#InlineEditor:constructor}
* empty_msg - (*string, optional*) the message to show when the element is empty. You can use html.
* hide_buttons - (*bool, optional*) hides the 'save' and 'cancel' buttons, use ENTER to submit, ESC to cancel.
* options_list - (*array, optional*) an array of objects in the form {'value':1, 'text':'one'}. These will be the options in the Dropdown
+* selected - (*string*) the value of the currently selected item, if this is not set, the first item will be selected.
### Events:
View
2 README.md
@@ -2,7 +2,7 @@ InlineEditor
============
InlineEditor allows any text element to be made editable. The user clicks on it, and it turns into a textbox with
-a save and cancel button. On save a request is send to the server with the new value, and any other needed metadata.
+a save and cancel button. On save a request is sent to the server with the new value, and any other needed metadata.
![ScreenShot](http://imgur.com/ZGoDz.png)
View
10 Source/InlineEditor.Combo.js
@@ -22,6 +22,7 @@ InlineEditor.Combo = new Class({
this.element = $(elem);
this.options = options || {};
this.options.options_list = this.options.options_list || this._read_options() || [];
+ this.options.selected = this.options.selected || this.element.get('data-selected');
this.parent(this.element, this.options);
@@ -59,6 +60,13 @@ InlineEditor.Combo = new Class({
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
// item.
@@ -104,7 +112,7 @@ InlineEditor.Combo = new Class({
_set_link: function() {
this.selectedIndex = this.edit_input.selectedIndex;
- this.current_text = this.edit_input.options[this.selectedIndex].text;;
+ 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
@@ -103,7 +103,7 @@
<div id='no-url'>no url</div>
-<div id='color-select'>
+<div id='color-select' data-selected='#0F0'>
<div data-value='#F00'>Red</div>
<div data-value='#0F0'>Green</div>
<div data-value='#00F'>Blue</div>

0 comments on commit 10134ba

Please sign in to comment.