forked from ionic-team/ionic-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathform.ts
More file actions
63 lines (53 loc) · 1.32 KB
/
form.ts
File metadata and controls
63 lines (53 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { Injectable } from '@angular/core';
/**
* @private
*/
@Injectable()
export class Form {
private _focused: any = null;
private _ids: number = -1;
private _inputs: any[] = [];
register(input: any) {
this._inputs.push(input);
}
deregister(input: any) {
let index = this._inputs.indexOf(input);
if (index > -1) {
this._inputs.splice(index, 1);
}
if (input === this._focused) {
this._focused = null;
}
}
focusOut() {
let activeElement = <HTMLElement>document.activeElement;
activeElement && activeElement.blur && activeElement.blur();
}
setAsFocused(input: any) {
this._focused = input;
}
/**
* Focuses the next input element, if it exists.
*/
tabFocus(currentInput: any) {
let index = this._inputs.indexOf(currentInput);
if (index > -1 && (index + 1) < this._inputs.length) {
let nextInput = this._inputs[index + 1];
if (nextInput !== this._focused) {
console.debug('tabFocus, next');
return nextInput.initFocus();
}
}
index = this._inputs.indexOf(this._focused);
if (index > 0) {
let previousInput = this._inputs[index - 1];
if (previousInput) {
console.debug('tabFocus, previous');
previousInput.initFocus();
}
}
}
nextId() {
return ++this._ids;
}
}