标签: form-control

Angular 6,this.formGroup.updateValueAndValidity() 无法正常工作

我正在尝试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

8
推荐指数
3
解决办法
1万
查看次数

同时激活表单和进程按钮单击?

我在C#中使用Windows窗体.

我有一个主窗体,其中包含几个包含toolStripButtons的工具栏.使用包含数据的另一个表单后,主窗体失去焦点并单击toolStripButton不会触发OnClick事件:第一次单击激活主窗体,只有第二次单击实际按下按钮.我需要用户只按一次按钮才能触发Click事件,有关如何操作的任何想法?谢谢.

笔记:

  • 我正在使用MDI,点击父母的表单按钮没有问题.但现在最重要的是让表格在多个显示器上自由浮动.
  • 工作者表单具有作为所有者属性的主要表单,这样它们保持在主表单的顶部.
  • 当我单击非活动表单的按钮时,MouseHover,MouseEnter,MouseDown和MouseUp都不会触发.这只是主要形式的激活事件.
  • 在主窗体上有一个treeView(在tabControl内,在splitContainer内,在一个面板内).即使主窗体处于非活动状态,也可以在第一次鼠标单击时选择其项目.我猜不是所有的控制都是平等的!

c# focus winforms form-control

7
推荐指数
1
解决办法
2954
查看次数

不会从'react-bootstrap'导出'ControlLabel'

您好,我正在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)

reactjs form-control

7
推荐指数
4
解决办法
1万
查看次数

UntypedFormControl 和 FormControl 之间的区别 #Angular14 #AngularMigration

我最近从 Angular12 迁移到 Angular14,Angular 在某些地方自动将 FormControl 转换为 UntypedFormControl。我观察到,在我使用 FormControl 的某些组件中,它仍然写为 FormControl。因此,我对哪些标准或在哪些条件下将 FormControl 角度转换为 UntypedFormControl 以及为什么在某些地方它仍然是 FormControl 感到有点困惑。我知道 UntypedFormControl 只是指向任何类型的 FormControl。

当我比较这两种情况时,我没有发现编码以及创建和使用 formGroup 和 formControl 的方式有任何差异。这让我更加困惑。

提前致谢!

formbuilder form-control formgroups angular14 angular-migration

7
推荐指数
1
解决办法
1709
查看次数

如何在C#中停靠窗体?

我只是想知道是否可以将窗体停靠在用户屏幕的顶部?我一直试图通过手动将表单的位置设置为我想要的坐标来做到这一点.但是,使用此方法,用户只需拖动即可更改表单的位置.我想使表单停靠在屏幕的上半部分,因为这个窗口表单将作为我正在制作的项目的菜单服务器.

非常感谢.:)

c# window dock winforms form-control

6
推荐指数
1
解决办法
2万
查看次数

如何在winforms中第二次"顺利"展示表格?

我有一个表单,应该通过点击主窗体中的按钮显示,我想当用户关闭第二个窗体时,主窗体再次显示在屏幕的中心.我使用下面的代码来做到这一点:

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)

这些命令做我想要的,但问题是关闭第二个窗体后,主窗体会显示一个小跳跃,就像眨眼一样!(它不是连续的,它只是在第一个.)我想要的是顺利完成,没有任何眨眼.这怎么可能?

提前致谢.

c# winforms form-control

6
推荐指数
1
解决办法
886
查看次数

Angular FormArray:引用模板中动态添加的FormControl

我正在使用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

6
推荐指数
1
解决办法
5330
查看次数

Angular 5 SelectControlValueAccessor 实现错误

我想在 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)

form-control angular-components angular angular5

5
推荐指数
1
解决办法
4114
查看次数

访问 FormArray 内 FormGroup 中的 FormControl

我正在尝试在 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 文件: …

form-control angular-material angular

5
推荐指数
1
解决办法
6338
查看次数

为什么 Angular ReactiveForms FormArray 会抛出错误“TypeError:无法读取 null 的属性‘updateOn’”

大家好,我有一个具有一组角色的 Formarray。在编辑期间,它会动态删除并在该表单数组中添加角色,直到这里一切正常,但是当我提交表单时,它会引发错误并且页面会刷新。

错误:TypeError:无法读取 null 的属性“updateOn”

我还附上了下面的屏幕截图在此处输入图片说明

form-control angular-reactive-forms formarray angular6

5
推荐指数
1
解决办法
1717
查看次数