mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
fixes #9699 fixes #11484 fixes #11389 fixes #11325 fixes #11291 fixes #10828 fixes #11291 fixes #10393 fixes #10257 fixes #9434 fixes #8933 fixes #7178 fixes #7047 fixes #10552 fixes #10393 fixes #10183 fixes #10187 fixes #10852 fixes #11578
89 lines
1.6 KiB
TypeScript
89 lines
1.6 KiB
TypeScript
import { Injectable } from '@angular/core';
|
|
import { removeArrayItem } from './util';
|
|
|
|
|
|
/**
|
|
* @hidden
|
|
*/
|
|
@Injectable()
|
|
export class Form {
|
|
|
|
private _focused: IonicFormInput = null;
|
|
private _ids: number = -1;
|
|
private _inputs: IonicFormInput[] = [];
|
|
|
|
register(input: IonicFormInput) {
|
|
this._inputs.push(input);
|
|
}
|
|
|
|
deregister(input: IonicFormInput) {
|
|
removeArrayItem(this._inputs, input);
|
|
this.unsetAsFocused(input);
|
|
}
|
|
|
|
setAsFocused(input: IonicFormInput) {
|
|
this._focused = input;
|
|
}
|
|
|
|
unsetAsFocused(input: IonicFormInput) {
|
|
if (input === this._focused) {
|
|
this._focused = null;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Focuses the next input element, if it exists.
|
|
*/
|
|
tabFocus(currentInput: IonicFormInput) {
|
|
const inputs = this._inputs;
|
|
let index = inputs.indexOf(currentInput) + 1;
|
|
if (index > 0 && index < inputs.length) {
|
|
var nextInput = inputs[index];
|
|
if (nextInput !== this._focused) {
|
|
console.debug('tabFocus, next');
|
|
return nextInput.initFocus();
|
|
}
|
|
}
|
|
|
|
index = inputs.indexOf(this._focused);
|
|
if (index > 0) {
|
|
var previousInput = inputs[index - 1];
|
|
if (previousInput) {
|
|
console.debug('tabFocus, previous');
|
|
previousInput.initFocus();
|
|
}
|
|
}
|
|
}
|
|
|
|
nextId() {
|
|
return ++this._ids;
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* @hidden
|
|
*/
|
|
export abstract class IonicTapInput implements IonicFormInput {
|
|
|
|
abstract initFocus(): void;
|
|
|
|
abstract get checked(): boolean;
|
|
|
|
abstract set checked(val: boolean);
|
|
|
|
abstract get disabled(): boolean;
|
|
|
|
abstract set disabled(val: boolean);
|
|
|
|
}
|
|
|
|
/**
|
|
* @hidden
|
|
*/
|
|
export abstract class IonicFormInput {
|
|
|
|
abstract initFocus(): void;
|
|
|
|
}
|