Commit 6030db61 authored by Sindre Sorhus's avatar Sindre Sorhus

Merge pull request #708 from kamilogorek/knockout-trimming

Knockout input value trimming on edit
parents bcd7682d 084b0664
......@@ -111,7 +111,17 @@
self.stopEditing = function (item) {
item.editing(false);
if (!item.title().trim()) {
var title = item.title();
var trimmedTitle = title.trim();
// Observable value changes are not triggered if they're consisting of whitespaces only
// Therefore we've to compare untrimmed version with a trimmed one to chech whether anything changed
// And if yes, we've to set the new value manually
if (title !== trimmedTitle) {
item.title(trimmedTitle);
}
if (!trimmedTitle) {
self.remove(item);
}
};
......
......@@ -50,7 +50,17 @@ define([
self.stopEditing = function (item) {
item.editing(false);
if (!item.title().trim()) {
var title = item.title();
var trimmedTitle = title.trim();
// Observable value changes are not triggered if they're consisting of whitespaces only
// Therefore we've to compare untrimmed version with a trimmed one to chech whether anything changed
// And if yes, we've to set the new value manually
if (title !== trimmedTitle) {
item.title(trimmedTitle);
}
if (!trimmedTitle) {
self.remove(item);
}
};
......
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