Commit 4f650776 authored by kamilogorek's avatar kamilogorek

Backbone input value trimming on edit

parent 2191e029
......@@ -67,11 +67,18 @@ var app = app || {};
// Close the `"editing"` mode, saving changes to the todo.
close: function () {
var trimmedValue = this.$input.val().trim();
this.$input.val(trimmedValue);
var value = this.$input.val();
var trimmedValue = value.trim();
if (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 {
this.clear();
}
......
......@@ -67,10 +67,18 @@ define([
// Close the `"editing"` mode, saving changes to the todo.
close: function () {
var value = this.$input.val().trim();
if (value) {
this.model.save({ title: value });
var value = this.$input.val();
var trimmedValue = value.trim();
if (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 {
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