dev #14607 Море. Правки по сайту: set cursor position at beginning of date input on focus

This commit is contained in:
nikolay 2023-07-05 15:25:58 +04:00
parent 73de9ea6b7
commit eb15e47328
2 changed files with 42 additions and 29 deletions

View File

@ -20,7 +20,7 @@
</mat-form-field>
<mat-form-field appearance="outline">
<mat-label>Дата рождения</mat-label>
<input formControlName="date" matInput [textMask]="mask" type="text" inputmode="numeric">
<input (click)="focusHandler($event)" (blur)="blurHandler()" formControlName="date" matInput [textMask]="mask" type="text" inputmode="numeric">
</mat-form-field>
<button mat-raised-button color="primary">Зарегистрироваться</button>
</div>

View File

@ -1,4 +1,4 @@
import { Component, OnInit } from "@angular/core";
import { Component } from "@angular/core";
import { FormControl, FormGroup, Validators } from "@angular/forms";
import { MessageService } from "primeng/api";
import { AuthService } from "src/app/services/auth.service";
@ -9,7 +9,7 @@ import moment from 'moment';
templateUrl: './create_user.component.html',
styleUrls: ['./create_user.component.scss'],
})
export class CreateUserComponent implements OnInit {
export class CreateUserComponent {
public form = new FormGroup({
name: new FormControl('', [Validators.required]),
sex: new FormControl('', [Validators.required]),
@ -27,7 +27,20 @@ export class CreateUserComponent implements OnInit {
private messageService: MessageService,
) { }
ngOnInit() { }
focused = false;
focusHandler(e: any) {
if (!this.focused) {
e.target.blur();
e.target.setSelectionRange(0, 0);
this.focused = true;
e.target.focus();
}
}
blurHandler() {
this.focused = false;
}
submit() {
if (this.form.invalid) {