我正在尝试formGroup根据特定条件在控件中添加和删除验证器。
当我更新formGroup.updateValueAndValidity()整个表单的验证器时,它没有更新,好像我专门申请每个控件,即formGroup.get('formControl').updateValueAndValidity(),它正在工作,但我必须为每个控件编写,我希望这不是正确的方法。我究竟做错了什么?
if (data == 'x') {
this.myForm.get('control2').setValue(null);
this.myForm.get('control2').setValidators(Validators.nullValidator);
this.myForm.get('control1').setValidators(Validators.required);
} else if (data == 'y') {
this.myForm.get('control1').setValue(null);
this.myForm.get('control1').setValidators(Validators.nullValidator);
this.myForm.get('control2').setValidators(Validators.required);
}
this.myForm.get('control1').updateValueAndValidity();
this.myForm.get('control2').updateValueAndValidity();
Run Code Online (Sandbox Code Playgroud)
这是有效的,但是,
this.myForm.updateValueAndValidity();
Run Code Online (Sandbox Code Playgroud)
这是行不通的。
typescript form-control angular formgroups angular-validator
我在C#中使用Windows窗体.
我有一个主窗体,其中包含几个包含toolStripButtons的工具栏.使用包含数据的另一个表单后,主窗体失去焦点并单击toolStripButton不会触发OnClick事件:第一次单击激活主窗体,只有第二次单击实际按下按钮.我需要用户只按一次按钮才能触发Click事件,有关如何操作的任何想法?谢谢.
笔记:
您好,我正在React中创建一个登录表单,以使用软件包的Checkbel来检查登录参数,但是当我运行代码时,我抛出了此异常: ./src/App.js尝试导入错误:“ ControlLabel”为不是从'react-bootstrap'导出的。我该如何解决?
反应代码:
import React, { Component } from "react";
import { Form,Button, FormGroup, FormControl, ControlLabel } from "react-bootstrap";
import "./Login.css";
import Bootstrap from "react-bootstrap";
export default class Login extends Component {
constructor(props) {
super(props);
this.state = {
email: "",
password: ""
};
}
validateForm() {
return this.state.email.length > 0 && this.state.password.length > 0;
}
handleChange = event => {
this.setState({
[event.target.id]: event.target.value
});
}
handleSubmit = event => {
event.preventDefault();
}
render() {
return (
<div className="Login"> …Run Code Online (Sandbox Code Playgroud) 我最近从 Angular12 迁移到 Angular14,Angular 在某些地方自动将 FormControl 转换为 UntypedFormControl。我观察到,在我使用 FormControl 的某些组件中,它仍然写为 FormControl。因此,我对哪些标准或在哪些条件下将 FormControl 角度转换为 UntypedFormControl 以及为什么在某些地方它仍然是 FormControl 感到有点困惑。我知道 UntypedFormControl 只是指向任何类型的 FormControl。
当我比较这两种情况时,我没有发现编码以及创建和使用 formGroup 和 formControl 的方式有任何差异。这让我更加困惑。
提前致谢!
formbuilder form-control formgroups angular14 angular-migration
我只是想知道是否可以将窗体停靠在用户屏幕的顶部?我一直试图通过手动将表单的位置设置为我想要的坐标来做到这一点.但是,使用此方法,用户只需拖动即可更改表单的位置.我想使表单停靠在屏幕的上半部分,因为这个窗口表单将作为我正在制作的项目的菜单服务器.
非常感谢.:)
我有一个表单,应该通过点击主窗体中的按钮显示,我想当用户关闭第二个窗体时,主窗体再次显示在屏幕的中心.我使用下面的代码来做到这一点:
private void button_Click(object sender, EventArgs e)
{
this.Hide(); //Hides the main form .
form2.ShowDialog(); //Shows the second form .
this.Show(); // Re-shows the main form after closing the second form ( just in the taskbar , not on the screen ) .
this.StartPosition = FormStartPosition.CenterScreen; // I write this code because I want to show the main form on the screen , not just in the taskbar .
}
Run Code Online (Sandbox Code Playgroud)
这些命令做我想要的,但问题是关闭第二个窗体后,主窗体会显示一个小跳跃,就像眨眼一样!(它不是连续的,它只是在第一个.)我想要的是顺利完成,没有任何眨眼.这怎么可能?
提前致谢.
我正在使用Angular Reactive表单,已向FormArray中动态添加了两个FormControl,但是在将它们与formControlName绑定时,却无法在模板中引用这些FormControl。在模板中,我将循环索引变量“ i”分配给formControlName,但它不起作用。通过将控件与formControlName绑定,可以得到“具有路径的窗体控件没有值访问器”。这是我的组件类代码:
export class Control {
constructor(public controlType?: string, public label?: string, public required?: boolean, public placeholder?: string,
public options?: string[], public value?: string) { }
}
export class FormComponent implements OnInit {
reviewForm: FormGroup;
constructor(public formService: FormService, public dialog: MdDialog) { }
selectedControl: any = null;
label: string;
ngOnInit() {
this.reviewForm = new FormGroup({
'controlArray': new FormArray([
])
});
}
addControl() {
const myControl: Control = new Control(this.selectedControl.name, this.label, this.isRequired,
this.selectedControl.attributes.value, this.selectedControl.attributes.options, 'null');
var control: FormControl = new …Run Code Online (Sandbox Code Playgroud) form-control angular angular-reactive-forms angular-forms formarray
我想在 Angular 5 中创建一个自定义选择输入控件。我有一个实现 SelectControlValueAccessor 的组件。当我实现如下所示的课程时。它在代码注释中给出了错误。
import { Component, Input, forwardRef, SimpleChanges, OnChanges } from '@angular/core';
import { SelectControlValueAccessor } from '@angular/forms';
import { SELECT_VALUE_ACCESSOR } from '@angular/forms/src/directives/select_control_value_accessor';
@Component({
selector: 'select-input',
template: ` `,
providers: [
{
provide: SELECT_VALUE_ACCESSOR,
useExisting: forwardRef(() => SelectInputComponent),
multi: true
}
]
})
/*
[ts]
Class 'SelectInputComponent' incorrectly implements class 'SelectControlValueAccessor'. Did you mean to extend 'SelectControlValueAccessor' and inherit its members as a subclass?
Property '_renderer' is missing in type 'SelectInputComponent'.
class SelectInputComponent
*/
export …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 formarray 中的 formcontrol 上实现材料自动更正,但是当我尝试访问 ts 文件中的 formcontrol 时,它无法访问它。谁能帮帮我吗。
html 文件:
<div formArrayName="applicants">
<div *ngFor="let applicant of appForm.controls.applicants.controls; let i=index; let last = last">
<div [formGroupName]="i">
<div class="row">
<label for="applicant_short_name" class="col-sm-3 form-control-label">Applicant {{i+1}}</label>
<div class="col-sm-7">
<div class="form-group">
<!-- <input type="text" formControlName="applicant_short_name" class="form-control" id="inputFirstName" placeholder="Applicant"> -->
<!-- <mat-form-field > -->
<input type="text" class="form-control" id="inputFirstName" placeholder="Applicant" [matAutocomplete]="auto" [formControlName]="applicant_short_name">
<mat-autocomplete #auto="matAutocomplete">
<mat-option *ngFor="let state of filteredNames | async | slice:0:3" [value]="name">
<span>{{ name }}</span>
</mat-option>
</mat-autocomplete>
<!-- </mat-form-field> -->
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
.ts 文件: …
大家好,我有一个具有一组角色的 Formarray。在编辑期间,它会动态删除并在该表单数组中添加角色,直到这里一切正常,但是当我提交表单时,它会引发错误并且页面会刷新。
错误:TypeError:无法读取 null 的属性“updateOn”
form-control ×10
angular ×4
c# ×3
winforms ×3
formarray ×2
formgroups ×2
angular14 ×1
angular5 ×1
angular6 ×1
dock ×1
focus ×1
formbuilder ×1
reactjs ×1
typescript ×1
window ×1