Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ember input value trimming and text selection removal #706

Merged
merged 1 commit into from
Oct 31, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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').
//
Expand All @@ -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);
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 2 additions & 0 deletions architecture-examples/emberjs/js/views/edit_todo_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
});
Expand Down