Class wwEditable

Extender class that makes a single DOM content element editable. Typically it is used with text div tags or more commonly yet with table cells.

This class on its own is not very useful. To work with the class you need to instantiate it and call its edit method explicitly. The preferred way to interact with the class is through the jQuery plug-in methods:

// *** Make a single column in a table editable var sel = jQuery(".nameColumn").makeEditable(nameChanged,{ updatedColor: red } ); function nameChanged(value, editable) { if (editable.origText == editable.enteredText) { showMessage("nothing has changed."); return false; } return true; // update content | false: abort | null: leave editing active }

It also supports making tables editable one cell at a time with some smarts about keyboard navigation via Tab keys.

This class uses jQuery and also expose a couple of jQuery plugin points:


var ctl = new wwEditable("divContent",contentEdited,{ updatedColor: "green", extraData: "myfield" } ); ... ctl.edit(); ... ctl.update(); // ctl.abort()

Class Members

MemberDescription
Constructor The constructor for wwEditable takes a single editable element and a callback function that is called when edit focus is lost.
abort Aborts the current editing operation. Automatically called in synchronous editing unless null is returned from the callback in which case you can asynchronously call abort() to cause editing changes to be discarded and original content to be restored.
o.wwEditable.abort()
edit Starts editing of the the control.
o.wwEditable.edit()
jQuery.makeEditable jQuery plug in method that allows making any selected elements editable in batch.
o.wwEditable.jQuery.makeEditable(selector,callback,options)
jQuery.makeTableEditable jQuery plug in method that allows making an entire table editable. All of the TD tags become editable.
o.wwEditable.jQuery.makeTableEditable(selector,callback,options)
nextColumn Tries to activate the next column for editing. Typically called after update() or abort() in the callback method to explictly force formatting.
o.wwEditable.nextColumn()
update Commits entered text changes to the original element. This occurs automatically in synchronous operation but you can call update() to commit changes in asynchronous situations such as AJAX callbacks to commit changes.
o.wwEditable.update()
callback The Callback function that is called. Set with the constructor typically but it's here so you can override.
enteredText The text the user entered when editing. Available in the callback method to allow you to compare agains the original text to determine if entry has been changed.
extraData Any extra data you want to assign to the editable. Consider this a generic 'state' field that you can use to attach data such as a column name that you later need to recover when the callback is fired.
jcol jQuery instance of the element that is editable.
jedit jQuery instance of the edit control (while it's active). Accessible in the callback method.
origHtml The original HTML content before the cell was edited. This is used in the abort method to restore the original Html.
origText The original text that was displayed for editing.
textMode Can be either "text" or "multiline". Determines how editing is handled - multi-line shows a text area and allows enter key entry.
updatedColor A color value that is applied to a little tick mark displayed in the the element once it's been updated.

Requirements

See also:

Class wwEditable

  Last Updated: 1/28/2008 | © West Wind Technologies, 2008