Skip to content

Commit

Permalink
created a shadow field for title , so that if the user closes the pag…
Browse files Browse the repository at this point in the history
…e while editing, the title is not affected, only the shadow is change which gets discarded.
  • Loading branch information
abhinavgujjar committed Aug 21, 2013
1 parent 71877d5 commit 1b2df76
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion labs/dependency-examples/durandal/js/viewmodels/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ define([
var Todo = function (title, completed) {
this.title = ko.observable(title);
this.completed = ko.observable(completed);
this.editTitle = ko.observable(title) //we use this as a shadow for the title so that if the user exits without saving, it is not persisted.
this.editing = ko.observable(false);
};

Expand Down Expand Up @@ -91,7 +92,7 @@ define([
item.editing(false);

//trim and save back
var trimmed = item.title().trim();
var trimmed = item.editTitle().trim();
item.title(trimmed);

if (!trimmed) {
Expand Down
2 changes: 1 addition & 1 deletion labs/dependency-examples/durandal/js/views/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<label data-bind="text: title, event: { dblclick: $root.editItem }"></label>
<button class="destroy" data-bind="click: $root.remove"></button>
</div>
<input class="edit" data-bind="value: title, valueUpdate: 'afterkeydown', enterKey: $root.stopEditing, selectAndFocus: editing, event: { blur: $root.stopEditing }">
<input class="edit" data-bind="value: editTitle, valueUpdate: 'afterkeydown', enterKey: $root.stopEditing, selectAndFocus: editing, event: { blur: $root.stopEditing }">
</li>
</ul>
</section>
Expand Down

0 comments on commit 1b2df76

Please sign in to comment.