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) {
// If you hit `enter`, we're through editing the item.
TodoView.prototype.updateOnEnter = function (e) {
if (e.which == TodoView.ENTER_KEY)
if (e.which === TodoView.ENTER_KEY)
this.close();
};
// If you're pressing `escape` we revert your change by simply leaving
// the `editing` state.
TodoView.prototype.revertOnEscape = function (e) {
if (e.which == TodoView.ESC_KEY) {
if (e.which === TodoView.ESC_KEY) {
this.$el.removeClass('editing');
// Also reset the hidden input back to the original value.
......@@ -285,10 +285,10 @@ var AppView = (function (_super) {
// If you hit return in the main input field, create new **Todo** model,
// persisting it to *localStorage*.
AppView.prototype.createOnEnter = function (e) {
if (e.keyCode != 13)
return;
Todos.create(this.newAttributes());
this.input.val('');
if (e.which === TodoView.ENTER_KEY && this.input.val().trim()) {
Todos.create(this.newAttributes());
this.input.val('');
}
};
// Clear all done todo items, destroying their models.
......
......@@ -238,13 +238,13 @@ class TodoView extends Backbone.View {
// If you hit `enter`, we're through editing the item.
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
// the `editing` state.
revertOnEscape(e) {
if (e.which == TodoView.ESC_KEY) {
if (e.which === TodoView.ESC_KEY) {
this.$el.removeClass('editing');
// Also reset the hidden input back to the original value.
this.input.val(this.model.get('content'));
......@@ -348,9 +348,10 @@ class AppView extends Backbone.View {
// If you hit return in the main input field, create new **Todo** model,
// persisting it to *localStorage*.
createOnEnter(e) {
if (e.keyCode != 13) return;
Todos.create(this.newAttributes());
this.input.val('');
if (e.which === TodoView.ENTER_KEY && this.input.val().trim()) {
Todos.create(this.newAttributes());
this.input.val('');
}
}
// Clear all done todo items, destroying their models.
......
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