Mixin: SC.InlineEditable
This mixin is used for views that show a seperate editor view to edit.
For example, the default behavior of SC.LabelView
if isEditable
is set
to YES
is to popup an SC.InlineTextFieldView
when double clicked. This is a
seperate text input that will handle the editing and save its value back to
the label when it is finished.
To use this functionality, all you have to do is apply this mixin to
your view. You may define your own SC.InlineEditorDelegate
to further
customize editing behavior.
MyProject.MyView = SC.View.extend(SC.InlineEditable, {
inlineEditorDelegate: myDelegate
});
The delegate methods will default to your view unless the
inlineEditorDelegate
implements them. Simple views do not require a
seperate delegate. If your view has a more complicated editing
interaction, you may also implement a custom delegate. For example, if
you have a form with several views that all edit together, you might
set the parent view as the delegate so it can manage the lifecycle and
layout of the editors.
See SC.InlineEditorDelegate
for more information on using a delegate to
customize your view's edit behavior.
Your view can now be edited by calling beginEditing
() on it.
myView.beginEditing();
This will create an editor for the view. You can then end the editing process
by calling commitEditing
() or discardEditing
() on either the view or the
editor. commitEditing
() will save the value and discard will revert to the
original value.
myView.commitEditing();
myView.discardEditing();
Note that the editor is a private property of the view, so the only views that should be able to access the methods on it are the editor itself, the view it is editing, and their delegates.
Defined in: inline_editable.js
Field Summary
- SC.InlineEditable.exampleEditor
- SC.InlineEditable.inlineEditorDelegate
- SC.InlineEditable.isEditable
- SC.InlineEditable.isEditing
- SC.InlineEditable.isInlineEditable
Class Methods
- beginEditing()
- commitEditing()
- discardEditing()
- inlineEditorDidBeginEditing(editor, value, editable)
- inlineEditorDidCommitEditing(editor, value, editable)
- inlineEditorDidDiscardEditing(editor, editable)
- inlineEditorShouldBeginEditing()
- inlineEditorWillBeginEditing(editor, value, editable)
- inlineEditorWillDiscardEditing(editor, editable)
Field Detail
SC.InlineEditable.exampleEditor SC.InlineEditorThe view that will be used to edit this view. Defaults to
SC.InlineTextFieldView
, which is simply a text field that positions itself
over the view being edited.
- Default value:
- SC.InlineTextFieldView
Delegate that will be notified of events related to the editing process. Also responsible for managing the lifecycle of the editor.
- Default value:
- SC.InlineTextFieldDelegate
- Default value:
- YES
Indicates whether the view is currently editing. Attempting to
beginEditing
a view that is already editing will fail.
- Default value:
- NO
- Default value:
- YES
Class Method Detail
Tells the view to start editing. This will create an editor for it and transfer control to the editor.
Will fail if the delegate returns NO
to inlineEditorShouldBeginEditing
.
- Returns:
- Boolean
- whether the view successfully entered edit mode
Tells the view to save the value currently in the editor and finish
editing. The delegate will be consulted first by calling
inlineEditorShouldCommitEditing
, and the operation will not be
allowed if the delegate returns NO
.
Will fail if the delegate returns NO
to inlineEditorShouldCommitEditing
.
- Returns:
- Boolean
- whether the delegate allowed the value to be committed
Tells the view to leave edit mode and revert to the value it had
before editing. May fail if the delegate returns NO
to
inlineEditorShouldDiscardEditing
. It is possible for the delegate to
return false to inlineEditorShouldDiscardEditing
but true to
inlineEditorShouldCommitEditing
, so a client view may attempt to
call commitEditing
in case discardEditing
fails.
Will fail if the delegate returns NO
to inlineEditorShouldDiscardEditing
.
- Returns:
- Boolean
- whether the delegate allowed the view to discard its value
- Parameters:
- editor
- value
- editable
By default, commiting editing simply sets the value that the editor returned and cleans up.
- Parameters:
- editor
- value
- editable
Calls inlineEditorDidEndEditing
for backwards compatibility and then
cleans up.
- Parameters:
- editor
- editable
Allows the view to begin editing if it is editable and it is not already editing.
- Returns:
- Boolean
- if the view is allowed to begin editing
- Parameters:
- editor
- value
- editable
- Parameters:
- editor
- editable