Skip to content

Commit

Permalink
allow for custom save/cancel text
Browse files Browse the repository at this point in the history
  • Loading branch information
nakajima committed Aug 7, 2008
1 parent f7558f4 commit ce88e71
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/editable.js
Expand Up @@ -32,9 +32,9 @@ var Editable = Class.create({
this.editForm = new Element('form', { 'action': this.element.readAttribute('rel'), 'style':'display:none', 'class':'editor' });
this.editInput = new Element(this.editFieldTag, { 'name':this.field, 'id':('edit_' + this.element.identify()) });
this.editInput.value = this.element.innerHTML;
var saveInput = new Element('input', { 'type':'submit', 'value':'Save' });
this.cancelLink = new Element('a', { 'href':'#' }); this.cancelLink.update('Cancel');
var methodInput = new Element('input', { 'type':'hidden', 'value':'put', 'name':'_method' });
var saveInput = new Element('input', { type:'submit', value: Editable.options.saveText });
this.cancelLink = new Element('a', { href:'#' }); this.cancelLink.update(Editable.options.cancelText);
var methodInput = new Element('input', { type:'hidden', value:'put', name:'_method' });
if (typeof(window._token) != 'undefined') {
this.editForm.insert(new Element('input', {
type: 'hidden',
Expand Down Expand Up @@ -107,6 +107,11 @@ var Editable = Class.create({
});

Object.extend(Editable, {
options: {
cancelText: 'Cancel',
saveText: 'Save'
},

create: function(element) {
new Editable(element);
},
Expand Down
16 changes: 16 additions & 0 deletions test/unit/editable_test.html
Expand Up @@ -63,6 +63,22 @@ <h1>Better Edit in Place test file</h1>
this.assertEqual('Cancel', cancel.innerHTML);
},

testShouldAllowCustomSaveLabels: function() {
this.list.editForm.remove();
Editable.options.saveText = 'done!'
this.list.setupForm();
var saveButton = this.list.editForm.select('input[type=submit]').first();
this.assertEqual('done!', saveButton.readAttribute('value'));
},

testShouldAllowCustomCancelLabels: function() {
this.list.editForm.remove();
Editable.options.cancelText = 'quit!'
this.list.setupForm();
var cancelLink = this.list.editForm.select('a').first();
this.assertEqual('quit!', cancelLink.innerHTML);
},

testShouldIncludeAuthTokenInEditForm: function() {
this.list.editForm.remove();
var auth_token = '9a41b076b0feb2dc1e22af58662647934c8cf4a8';
Expand Down

0 comments on commit ce88e71

Please sign in to comment.