Skip to content

Commit

Permalink
Add select() method and 'select' event to Text editors.
Browse files Browse the repository at this point in the history
  • Loading branch information
DouweM committed Jul 20, 2012
1 parent c581068 commit 389ac2a
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 2 deletions.
7 changes: 7 additions & 0 deletions distribution/backbone-forms.amd.js
Expand Up @@ -1100,6 +1100,9 @@ Form.editors = (function() {
self.determineChange();
}, 0);
},
'select': function(event) {
this.trigger('select', this);
},
'focus': function(event) {
this.trigger('focus', this);
},
Expand Down Expand Up @@ -1168,6 +1171,10 @@ Form.editors = (function() {
if (!this.hasFocus) return;

this.$el.blur();
},

select: function() {
this.$el.select();
}

});
Expand Down
2 changes: 1 addition & 1 deletion distribution/backbone-forms.amd.min.js

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions distribution/backbone-forms.js
Expand Up @@ -1118,6 +1118,9 @@ Form.editors = (function() {
self.determineChange();
}, 0);
},
'select': function(event) {
this.trigger('select', this);
},
'focus': function(event) {
this.trigger('focus', this);
},
Expand Down Expand Up @@ -1186,6 +1189,10 @@ Form.editors = (function() {
if (!this.hasFocus) return;

this.$el.blur();
},

select: function() {
this.$el.select();
}

});
Expand Down
2 changes: 1 addition & 1 deletion distribution/backbone-forms.min.js

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions src/editors.js
Expand Up @@ -162,6 +162,9 @@ Form.editors = (function() {
self.determineChange();
}, 0);
},
'select': function(event) {
this.trigger('select', this);
},
'focus': function(event) {
this.trigger('focus', this);
},
Expand Down Expand Up @@ -230,6 +233,10 @@ Form.editors = (function() {
if (!this.hasFocus) return;

this.$el.blur();
},

select: function() {
this.$el.select();
}

});
Expand Down
33 changes: 33 additions & 0 deletions test/editors.js
Expand Up @@ -216,6 +216,22 @@ module('Text', {
ok(spy.calledWith(field));
});

test("select() - triggers the 'select' event", function() {
var field = new editor({
model: new Post,
key: 'title'
}).render();

var spy = this.sinon.spy();

field.on('select', spy);

field.select();

ok(spy.called);
ok(spy.calledWith(field));
});

test("'change' event - is triggered when value of input changes", function() {
var field = new editor({
model: new Post,
Expand Down Expand Up @@ -311,6 +327,23 @@ module('Text', {
ok(spy.alwaysCalledWith(field));
});

test("'select' event - bubbles up from the input", function() {
var field = new editor({
model: new Post,
key: 'title'
}).render();


var spy = this.sinon.spy();

field.on('select', spy);

field.$el.select();

ok(spy.calledOnce);
ok(spy.alwaysCalledWith(field));
});

test('Default type is text', function() {
var field = new editor().render();

Expand Down

0 comments on commit 389ac2a

Please sign in to comment.