Skip to content
This repository has been archived by the owner on May 25, 2018. It is now read-only.

Commit

Permalink
New data_id parameter added as shorthand for using {data:{id:'xxx'}}
Browse files Browse the repository at this point in the history
  • Loading branch information
reednj committed Aug 12, 2011
1 parent 5733ff6 commit 5bb765b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Docs/InlineEditor.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ InlineEditor Method: constructor {#InlineEditor:constructor}

### Options:
* url - (*string, optional*) url to send the save request to
* data - (*object, optional*) extra data to send along with the save request
* data - (*object, optional*) extra data to send along with the save request.
* data_id - (*string, optional*) Sohrthand method to pass in {data:{id:'xxx' }} on the object
* 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.
* format - (*string, optional*) A format code of the type Nx where x is the number of decimal places to format with. Only use this if the data type is numerical.
Expand Down
3 changes: 2 additions & 1 deletion Source/InlineEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var InlineEditor = new Class({
// set defaults...
this.options = options || {};
this.options.url = this.options.url || this.element.get('data-url');
this.options.data_id = this.options.data_id || this.element.get('data-id');
this.options.data = this.options.data || {};
this.options.empty_msg = this.options.empty_msg || this._empty_msg;
this.options.onSuccess = this.options.onSuccess || $empty;
Expand Down Expand Up @@ -169,7 +170,7 @@ var InlineEditor = new Class({
// set up the data to send to the server.
var request_data = $H({'value':new_value});
request_data.combine(this.options.data);
request_data.include('id', this.element.get('data-id')); // if 'id' already exists it will not be overwritten
request_data.include('id', this.options.data_id); // if 'id' already exists it will not be overwritten

var save_req = new Request({
'url': this.options.url,
Expand Down
8 changes: 8 additions & 0 deletions Test/simpletest.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@
$('color-target').setStyle('background-color', new_value);
}
});

new InlineEditor('jsonpost', {
url: 'api/edittest.php',
method: 'POST',
data_id: '12'
});
}
}

Expand Down Expand Up @@ -116,6 +122,8 @@

<div class='editable' data-format='N3'>123456.12345</div>

<div id='jsonpost'>hello, world</div>

</div>

</body>
Expand Down

0 comments on commit 5bb765b

Please sign in to comment.