Skip to content

Commit

Permalink
Making invalid inputs select themselves when validation fails
Browse files Browse the repository at this point in the history
  • Loading branch information
MeoMix committed May 20, 2015
1 parent c7d831a commit d27f379
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
10 changes: 10 additions & 0 deletions src/js/foreground/view/dialog/createPlaylistView.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@
this.ui.title.focus().val(this.ui.title.val());
},

onValidationFailed: function() {
var titleValid = this.model.get('titleValid');

if (!titleValid) {
this.ui.title.focus();
} else {
this.ui.dataSource.focus();
}
},

createPlaylist: function() {
var trimmedTitle = this._getTrimmedTitle();

Expand Down
2 changes: 2 additions & 0 deletions src/js/foreground/view/dialog/dialogView.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@
}

this._hide();
} else {
this.contentView.triggerMethod('ValidationFailed');
}
},

Expand Down
12 changes: 6 additions & 6 deletions src/js/foreground/view/dialog/editPlaylistView.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@
},

onAttach: function() {
this._focusInput();
// Reset val to prevent text from becoming highlighted.
this.ui.title.focus().val(this.ui.title.val());
},

onValidationFailed: function() {
this.ui.title.focus();
},

editPlaylist: function() {
Expand All @@ -54,11 +59,6 @@
this._validateTitle();
},

_focusInput: function() {
// Reset val to prevent text from becoming highlighted.
this.ui.title.focus().val(this.ui.title.val());
},

_validateTitle: function() {
// When the user submits - check to see if they provided a playlist name
var trimmedTitle = this._getTrimmedTitle();
Expand Down

0 comments on commit d27f379

Please sign in to comment.