Skip to content
This repository was archived by the owner on Dec 26, 2019. It is now read-only.

Commit 0334d96

Browse files
committed
Merge pull request #64 from octronic/support-focus-events
Support focus events
2 parents cd8ef76 + dc120d7 commit 0334d96

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,50 @@ Default: `0` (Sunday)
203203
{{bootstrap-datepicker value=expiresAt weekStart=1}}
204204
```
205205

206+
### Actions
207+
208+
#### changeDate
209+
210+
The changeDate action is triggered when the selected date changes. It can be specified like this:
211+
212+
213+
```handlebars
214+
{{bootstrap-datepicker changeDate="changeDateAction"}}
215+
```
216+
217+
The action can be handled by a parent component, controller or route:
218+
219+
```javascript
220+
actions {
221+
changeDateAction(date) {
222+
// do sth with the new date
223+
}
224+
}
225+
```
226+
227+
#### focus-in & focus-out
228+
229+
The focus-in and focus-out actions are triggered when the respective focus events occur on the input field.
230+
231+
```handlebars
232+
{{bootstrap-datepicker focus-in="focusInAction" focus-out="focusOutAction"}}
233+
```
234+
235+
The actions can be handled by a parent component, controller or route:
236+
237+
```javascript
238+
actions {
239+
focusInAction(component, event) {
240+
// handle event
241+
},
242+
focusOutAction(component, event) {
243+
// handle event
244+
}
245+
}
246+
```
247+
248+
249+
206250
## Contributing
207251

208252
1. Fork it

addon/components/datepicker-support.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ export default Ember.Mixin.create({
5252
if (!self.$().val()) {
5353
self._applyDateValue(null);
5454
}
55+
}).
56+
on('focusout', function(event) {
57+
self.sendAction('focus-out', self, event);
58+
}).
59+
on('focusin', function(event) {
60+
self.sendAction('focus-in', self, event);
5561
});
5662

5763
this._updateDatepicker();

tests/integration/components/bootstrap-datepicker-integration-test.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,38 @@ test('triggers changeDate action when input field is cleared', function (assert)
4949

5050
assert.ok(actionIsTriggered, 'action is triggered');
5151
});
52+
53+
test('triggers specified action on focusout event', function (assert) {
54+
assert.expect(1);
55+
56+
this.render(hbs`
57+
{{bootstrap-datepicker focus-out="focusOutAction"}}
58+
`);
59+
60+
var actionIsTriggered = false;
61+
this.on('focusOutAction', () => {
62+
actionIsTriggered = true;
63+
});
64+
65+
this.$('input.ember-text-field').trigger('focusout');
66+
67+
assert.ok(actionIsTriggered, 'action is triggered on focusout');
68+
});
69+
70+
71+
test('triggers specified action on focusin event', function (assert) {
72+
assert.expect(1);
73+
74+
this.render(hbs`
75+
{{bootstrap-datepicker focus-in="focusInAction"}}
76+
`);
77+
78+
var actionIsTriggered = false;
79+
this.on('focusInAction', () => {
80+
actionIsTriggered = true;
81+
});
82+
83+
this.$('input.ember-text-field').trigger('focusin');
84+
85+
assert.ok(actionIsTriggered, 'action is triggered on focusin');
86+
});

0 commit comments

Comments
 (0)