Commit 6a02061c authored by Sindre Sorhus's avatar Sindre Sorhus

Merge pull request #707 from kamilogorek/backbone-trimming

Backbone input value trimming on edit
parents 2191e029 4f650776
...@@ -67,11 +67,18 @@ var app = app || {}; ...@@ -67,11 +67,18 @@ var app = app || {};
// Close the `"editing"` mode, saving changes to the todo. // Close the `"editing"` mode, saving changes to the todo.
close: function () { close: function () {
var trimmedValue = this.$input.val().trim(); var value = this.$input.val();
this.$input.val(trimmedValue); var trimmedValue = value.trim();
if (trimmedValue) { if (trimmedValue) {
this.model.save({ title: trimmedValue }); this.model.save({ title: trimmedValue });
if (value !== trimmedValue) {
// Model values changes consisting of whitespaces only are not causing change to be triggered
// Therefore we've to compare untrimmed version with a trimmed one to chech whether anything changed
// And if yes, we've to trigger change event ourselves
this.model.trigger('change');
}
} else { } else {
this.clear(); this.clear();
} }
......
...@@ -67,10 +67,18 @@ define([ ...@@ -67,10 +67,18 @@ define([
// Close the `"editing"` mode, saving changes to the todo. // Close the `"editing"` mode, saving changes to the todo.
close: function () { close: function () {
var value = this.$input.val().trim(); var value = this.$input.val();
var trimmedValue = value.trim();
if (value) { if (trimmedValue) {
this.model.save({ title: value }); this.model.save({ title: trimmedValue });
if (value !== trimmedValue) {
// Model values changes consisting of whitespaces only are not causing change to be triggered
// Therefore we've to compare untrimmed version with a trimmed one to chech whether anything changed
// And if yes, we've to trigger change event ourselves
this.model.trigger('change');
}
} else { } else {
this.clear(); this.clear();
} }
......
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