Browse files

fixed keycode detection for text_field and text_area, added keycode d…

…etect test
  • Loading branch information...
1 parent 9865334 commit 13a841002b487bb67bdb479a35c6206dafe048f4 @jamesstrate jamesstrate committed Apr 4, 2013
Showing with 12 additions and 6 deletions.
  1. +1 −1 src/js/text_area.js
  2. +1 −1 src/js/text_field.js
  3. +10 −4 test/text_field.js
View
2 src/js/text_area.js
@@ -51,7 +51,7 @@
this.setEnabled(!this.options.disabled);
- $(this.textArea).input(_.bind(function() {
+ $(this.textArea).keyup(_.bind(function() {
_.defer(_(this._updateModel).bind(this));
}, this));
View
2 src/js/text_field.js
@@ -35,7 +35,7 @@
this.input = $.el.input({maxLength : this.options.maxLength});
- $(this.input).input(_(function(e) {
+ $(this.input).keyup(_(function(e) {
if(_(this.options.onKeyPress).exists() && _(this.options.onKeyPress).isFunction()) {
this.options.onKeyPress(e, this);
}
View
14 test/text_field.js
@@ -92,6 +92,7 @@ $(document).ready(function() {
test("onKeyPress", function() {
var countPress=0;
+ var enterPress=0;
var coffee = new Backbone.Model({
roaster: 'Counter Culture',
@@ -103,18 +104,23 @@ $(document).ready(function() {
var textfield = new Backbone.UI.TextField({
model : coffee,
content : 'roaster',
- onKeyPress : function() { countPress++; }
+ onKeyPress : function(e) {
+ countPress++;
+ if(e.keyCode === 13) enterPress++;
+ }
}).render();
- //enter a in text field
- $(textfield.el).find('input').simulate("key-sequence", {sequence: "a"});
- //wait 1 sec and check if keypress got called
+ //press the enter key in text field
+ $(textfield.el).find('input').simulate("key-sequence", {sequence: "{enter}"});
+ //wait 1 sec and check if keypress got called and detect keyCode
stop();
setTimeout(function(){
equal(countPress,1);
+ equal(enterPress,1);
start();
},1000);
+
});
test("tabIndex", function() {

0 comments on commit 13a8410

Please sign in to comment.