【发布时间】:2018-12-07 16:28:37
【问题描述】:
我做了类似谷歌验证码的功能,用户必须输入发送到他们电子邮件的号码,并且用户必须将该代码输入验证页面 我为用户输入了 6 个输入,如下所示:
每个都是不同名称的不同输入字段,例如 input1、input2、input3 等
我想让那个不同的名字只有一个名字有一个值。 像这样 输入:(231486)
不是这样的 输入1:(2) 输入2:(3) 输入3:(1) 等等
这是我的代码:
<form (ngSubmit)="otp(otpForm.value)" [formGroup]="otpForm">
<div fxLayout="row" fxLayoutAlign="center">
<table cellspacing="0" cellpadding="0">
<tr>
<ng-container>
<td class="otp__tdr">
<mat-form-field class="otp__field">
<input
#input1
matInput
maxlength="1"
formControlName="otp1"
(input)="onInputEntry($event, input2)"
/>
</mat-form-field>
</td>
<td>
<mat-form-field class="otp__field">
<input
#input2
matInput
maxlength="1"
formControlName="otp2"
(input)="onInputEntry($event, input3)"
/>
</mat-form-field>
</td>
<td>
<mat-form-field class="otp__field">
<input
#input3
matInput
maxlength="1"
formControlName="otp3"
(input)="onInputEntry($event, input4)"
/>
</mat-form-field>
</td>
<button type="submit" mat-raised-button color="primary">
Verify
</button>
</div>
</form>
它是我的一些打字稿:
export class OtpComponent implements OnInit {
otpForm: FormGroup;
// FormControl = new FormControl('');
constructor( private router: Router, private formBuilder: FormBuilder) { }
ngOnInit() {
this.otpForm = this.formBuilder.group({
otp1: ['', Validators.required],
otp2: ['', Validators.required],
otp3: ['', Validators.required],
otp4: ['', Validators.required],
otp5: ['', Validators.required],
otp6: ['', Validators.required]
});
}
onInputEntry(event, nextInput) {
const input = event.target;
const length = input.value.length;
const maxLength = input.attributes.maxlength.value;
if (length >= maxLength) {
nextInput.focus();
}
}
otp(otpForm) {
console.log('test otp', otpForm);
}
谁能帮帮我谢谢你的帮助
【问题讨论】:
-
请附上您尝试过的代码。
-
呃,它只是一个带有 CSS 的文本框?
-
我已经做了我的打字稿
标签: json angular typescript