Commit 5490f4de authored by Duilio Protti's avatar Duilio Protti Committed by Sindre Sorhus

Close GH-920: Typescript-backbone: do not create item on empty input. Fixes #919

parent d14b9463
...@@ -179,14 +179,14 @@ var TodoView = (function (_super) { ...@@ -179,14 +179,14 @@ var TodoView = (function (_super) {
// If you hit `enter`, we're through editing the item. // If you hit `enter`, we're through editing the item.
TodoView.prototype.updateOnEnter = function (e) { TodoView.prototype.updateOnEnter = function (e) {
if (e.which == TodoView.ENTER_KEY) if (e.which === TodoView.ENTER_KEY)
this.close(); this.close();
}; };
// If you're pressing `escape` we revert your change by simply leaving // If you're pressing `escape` we revert your change by simply leaving
// the `editing` state. // the `editing` state.
TodoView.prototype.revertOnEscape = function (e) { TodoView.prototype.revertOnEscape = function (e) {
if (e.which == TodoView.ESC_KEY) { if (e.which === TodoView.ESC_KEY) {
this.$el.removeClass('editing'); this.$el.removeClass('editing');
// Also reset the hidden input back to the original value. // Also reset the hidden input back to the original value.
...@@ -285,10 +285,10 @@ var AppView = (function (_super) { ...@@ -285,10 +285,10 @@ var AppView = (function (_super) {
// If you hit return in the main input field, create new **Todo** model, // If you hit return in the main input field, create new **Todo** model,
// persisting it to *localStorage*. // persisting it to *localStorage*.
AppView.prototype.createOnEnter = function (e) { AppView.prototype.createOnEnter = function (e) {
if (e.keyCode != 13) if (e.which === TodoView.ENTER_KEY && this.input.val().trim()) {
return;
Todos.create(this.newAttributes()); Todos.create(this.newAttributes());
this.input.val(''); this.input.val('');
}
}; };
// Clear all done todo items, destroying their models. // Clear all done todo items, destroying their models.
......
...@@ -238,13 +238,13 @@ class TodoView extends Backbone.View { ...@@ -238,13 +238,13 @@ class TodoView extends Backbone.View {
// If you hit `enter`, we're through editing the item. // If you hit `enter`, we're through editing the item.
updateOnEnter(e) { updateOnEnter(e) {
if (e.which == TodoView.ENTER_KEY) this.close(); if (e.which === TodoView.ENTER_KEY) this.close();
} }
// If you're pressing `escape` we revert your change by simply leaving // If you're pressing `escape` we revert your change by simply leaving
// the `editing` state. // the `editing` state.
revertOnEscape(e) { revertOnEscape(e) {
if (e.which == TodoView.ESC_KEY) { if (e.which === TodoView.ESC_KEY) {
this.$el.removeClass('editing'); this.$el.removeClass('editing');
// Also reset the hidden input back to the original value. // Also reset the hidden input back to the original value.
this.input.val(this.model.get('content')); this.input.val(this.model.get('content'));
...@@ -348,10 +348,11 @@ class AppView extends Backbone.View { ...@@ -348,10 +348,11 @@ class AppView extends Backbone.View {
// If you hit return in the main input field, create new **Todo** model, // If you hit return in the main input field, create new **Todo** model,
// persisting it to *localStorage*. // persisting it to *localStorage*.
createOnEnter(e) { createOnEnter(e) {
if (e.keyCode != 13) return; if (e.which === TodoView.ENTER_KEY && this.input.val().trim()) {
Todos.create(this.newAttributes()); Todos.create(this.newAttributes());
this.input.val(''); this.input.val('');
} }
}
// Clear all done todo items, destroying their models. // Clear all done todo items, destroying their models.
clearCompleted() { clearCompleted() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment