-
Notifications
You must be signed in to change notification settings - Fork 26.6k
Closed
Labels
Description
I'm submitting a ... (check one with "x")
[ ] bug report => search github for a similar issue or PR before submitting
[x] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
Current behavior
There seems to be no way to focus a FormControl.
Expected behavior
FormControl provides a .focus() instance method, or access to the native HTML element.
What is the motivation / use case for changing the behavior?
To give input focus to a control when it is invalid, as in the following example:
if (!this.form.valid) {
let invalid = <FormControl[]>Object.keys(this.form.controls).map(key => this.form.controls[key]).filter(ctl => ctl.invalid);
if (invalid.length > 0) {
// Give input focus to invalid[0]... how?
}
return false;
}
Please tell us about your environment:
-
Angular version: 2.2.1
-
Browser: N/A
-
Language: TypeScript 2.0.3
kemsky, logic01, GenesisSelf, wojo1206, pragatir and 10 more