Skip to content
Extraits de code Groupes Projets
Valider 61edda0f rédigé par Steffen van Bergerem's avatar Steffen van Bergerem
Parcourir les fichiers

Aspect creation modal now creates an aspect when pressing enter

parent db00bd1b
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -4,7 +4,8 @@ app.views.AspectCreate = app.views.Base.extend({ ...@@ -4,7 +4,8 @@ app.views.AspectCreate = app.views.Base.extend({
templateName: "aspect_create_modal", templateName: "aspect_create_modal",
events: { events: {
"click .btn.btn-primary": "createAspect" "click .btn.btn-primary": "createAspect",
"keypress input#aspect_name": "inputKeypress"
}, },
initialize: function(opts) { initialize: function(opts) {
...@@ -30,6 +31,13 @@ app.views.AspectCreate = app.views.Base.extend({ ...@@ -30,6 +31,13 @@ app.views.AspectCreate = app.views.Base.extend({
return this.$("#aspect_name").val(); return this.$("#aspect_name").val();
}, },
inputKeypress: function(evt) {
if(evt.which === 13) {
evt.preventDefault();
this.createAspect();
}
},
createAspect: function() { createAspect: function() {
var aspect = new app.models.Aspect({ var aspect = new app.models.Aspect({
"person_id": this._personId, "person_id": this._personId,
......
...@@ -40,6 +40,24 @@ describe("app.views.AspectCreate", function() { ...@@ -40,6 +40,24 @@ describe("app.views.AspectCreate", function() {
}); });
}); });
describe("#inputKeypress", function() {
beforeEach(function() {
this.view.render();
spyOn(this.view, "createAspect");
});
it("should call createAspect if the enter key was pressed", function() {
var e = $.Event("keypress", { which: 13 });
this.view.inputKeypress(e);
expect(this.view.createAspect).toHaveBeenCalled();
});
it("shouldn't call createAspect if another key was pressed", function() {
var e = $.Event("keypress", { which: 42 });
this.view.inputKeypress(e);
expect(this.view.createAspect).not.toHaveBeenCalled();
});
});
describe("#createAspect", function() { describe("#createAspect", function() {
beforeEach(function() { beforeEach(function() {
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter