Commit bcd7682d authored by Sindre Sorhus's avatar Sindre Sorhus

Merge pull request #706 from kamilogorek/ember-trimming

Ember input value trimming and text selection removal
parents 6a02061c 55b1bc7c
......@@ -15,9 +15,9 @@ Todos.TodoController = Ember.ObjectController.extend({
},
doneEditing: function () {
var bufferedTitle = this.get('bufferedTitle');
var bufferedTitle = this.get('bufferedTitle').trim();
if (Ember.isEmpty(bufferedTitle.trim())) {
if (Ember.isEmpty(bufferedTitle)) {
// The `doneEditing` action gets sent twice when the user hits
// enter (once via 'insert-newline' and once via 'focus-out').
//
......@@ -26,10 +26,12 @@ Todos.TodoController = Ember.ObjectController.extend({
Ember.run.debounce(this, this.send, 'removeTodo', 0);
} else {
var todo = this.get('model');
todo.set('title', this.get('bufferedTitle'));
todo.set('title', bufferedTitle);
todo.save();
}
// Re-set our newly edited title to persist it's trimmed version
this.set('bufferedTitle', bufferedTitle);
this.set('isEditing', false);
},
......
......@@ -8,8 +8,8 @@ Todos.TodosController = Ember.ArrayController.extend({
var title, todo;
// Get the todo title set by the "New Todo" text field
title = this.get('newTitle');
if (!title.trim()) {
title = this.get('newTitle').trim();
if (!title) {
return;
}
......
......@@ -3,6 +3,8 @@
Todos.EditTodoView = Ember.TextField.extend({
focusOnInsert: function () {
// Re-set input value to get rid of a reduntant text selection
this.$().val(this.$().val());
this.$().focus();
}.on('didInsertElement')
});
......
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