Mixin: SC.Editable

The Editable mixin is a standard protocol used to activate keyboard editing on views that are editable such as text fields, label views and item views.

You should apply this mixin, or implement the methods, if you are designing an item view for a collection and you want to automatically trigger editing.

Using Editable Views

To use a view that includes the Editable mixin, you simply call three methods on the view:

Implementing an Editable View

To implement a new view that is editable, you should implement the three methods defined below: beginEditing(), discardEditing(), and commitEditing(). If you already allow editing when your view becomes first responder and commit your changes when the view loses first responder status then you can simply apply this mixin and not override any methods.

Defined in: editable.js

Since:
SproutCore 1.0

Field Summary

Class Methods

Field Detail

SC.Editable.isEditable Boolean

Indicates whether a view is editable or not. You can optionally implement the methods in this mixin to disallow editing is isEditable is NO.

Default value:
NO
SC.Editable.isEditing Boolean

Indicates whether editing is currently in progress. The methods you implement should generally up this property as appropriate when you begin and end editing.

Default value:
NO

Class Method Detail

beginEditing()

Begins editing on the view.

This method is called by other views when they want you to begin editing. You should write this method to become first responder, perform any additional setup needed to begin editing and then return YES.

If for some reason you do not want to allow editing right now, you can also return NO. If your view is already editing, then you should not restart editing again but just return YES.

The default implementation checks to see if editing is allowed, then becomes first responder and updates the isEditing property if appropriate. Generally you will want to replace this method with your own implementation and not call the default.

Returns:
Boolean
YES if editing began or is in progress, NO otherwise
commitEditing()

Ends editing on the view, committing any changes that were made to the view value in the meantime.

This method is called by other views when they want to end editing, saving any changes that were made to the view in the meantime. When this method is called you should resign first responder, save the latest value of the view and return YES.

If your view cannot save the current state of the view for some reason (for example if validation fails), then you should return NO. Properly implemented clients may then try to call discardEditing() to force your view to resign first responder anyway.

Some views apply changes to their value immediately during an edit instead of waiting for the view to end editing. If this is the case, you should still implement commitEditing but you simply may not save any value changes.

If this method is called on a view that is not currently editing, you should always just return YES.

The default implementation sets isEditing to NO, resigns first responder and returns YES.

Returns:
Boolean
YES if changes were discarded and editing ended.
discardEditing()

Ends editing on the view, discarding any changes that were made to the view value in the meantime.

This method is called by other views when they want to cancel editing that began earlier. When this method is called you should resign first responder, restore the original value of the view and return YES.

If your view cannot revert back to its original state before editing began then you can implement this method to simply return NO. A properly implemented client may try to call commitEditing() instead to force your view to end editing anyway.

If this method is called on a view that is not currently editing, you should always just return YES.

The default implementation does not support discarding changes and always returns NO.

Returns:
Boolean
YES if changes were discarded and editing ended.
Documentation generated by JsDoc Toolkit 2.4.0 on Wed Apr 08 2015 10:02:20 GMT-0600 (CST)