标签: form-control

角度2:通过FormControl获取FormGroup

我可以获取FormGroup-我拥有的FormControl的父级吗?像这样:

    onBlur(formControl: FormControl) {
    var formGroup = formControl.parent // a FormGroup has the FormControl
    if (formControl.dirty) {

        console.log(formControl);
    }

}
Run Code Online (Sandbox Code Playgroud)

form-control angular

3
推荐指数
2
解决办法
5309
查看次数

FormControl值是否可以是数组?

我正在研究Angular反应形式。这是我的组件类代码:

ngOnInit(){
        this.reviewForm = this.fb.group({            
            'controlArray': new FormArray([])
        });        
        this.showDefaultForm();                     
    }

addForm() {
    (<FormArray>this.reviewForm.get('controlArray')).push(this.fb.group({
        controlType: control.controlType,
        options: control.options,

    }));
}
Run Code Online (Sandbox Code Playgroud)

我收到TypeError:this.validator不是与此相关的函数。我认为这是由于将字符串数组(即control.options)分配为FormControl的值。如果我将其设置为FormArray,则此错误将解决,但是我在将其作为FormArray处理为模板时遇到了问题。请告诉我是否不使用FormArray,可以将字符串数组作为值分配给FormControl吗?如果没有,那么如何在模板中将其作为FormArray处理。谢谢

form-control angular angular-reactive-forms formarray

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

Angular FormControl检查(如果需要)

有没有办法检查是否需要控制?

当我实现它接受一个专用表单字段部件的问题出现FormControl,并不仅input也验证错误。由于某些字段是必填字段,因此最好让用户知道是否需要*

有没有一种方法来检查@Input() control: FormControlValidators.required,并显示一个星号?

validation form-control reactive-forms angular

2
推荐指数
3
解决办法
5864
查看次数

如何将 [formControlName] 与 mat-checkbox 一起使用

在 Angular Material 文档中,他们说[formControlName]不能与mat-checkbox. 如何根据值数组动态创建复选框并使用反应式表单获取复选框值?还有其他方法吗?

typescript form-control angular-material angular angular-reactive-forms

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

如何在 Angular 15 中通过条件禁用反应表单中的输入 FormControl?

我有一个可以输入学生 ID 的表格。下面是两个输入框,全名和电子邮件。当我加载页面时,仅应启用学生 ID 输入框,并禁用其下方的两个输入。当我输入学生 ID 并且它有记录时,这是唯一一次启用全名和电子邮件的输入框。

当我使用 Angular 13 时,它能够对每个输入进行处理

[attr.disable]="!isStudentIdReal"
Run Code Online (Sandbox Code Playgroud)

然而,我最近更新到 Angular 15,它就停止工作了。我能够找到一个解决方案:

studentName : [{value: '', disable: true}],
email : [{value: '', disable: true}]
Run Code Online (Sandbox Code Playgroud)

这会禁用输入框,但是不会启用它们,因为我没有条件。

form-control angular formgroups angular15

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

Windows窗体窗口始终关注?

我知道有一些线索已经存在.我需要的是一个窗体窗口总是聚焦意味着如果我点击记事本或任何程序它不会输入任何数据,只在我的窗体文本框中输入数据.

我发现这个代码在某种程度上可以解释更多

    //Delegates for safe multi-threading.
    delegate void DelegateGetFocus();
    private DelegateGetFocus m_getFocus;
    Thread newThread;

    public MemberLogin()
    {

        m_getFocus = new DelegateGetFocus(this.getFocus);  
        InitializeComponent();
        spawnThread(keepFocus);
        toggleFocusButton.Text = "OFF";
        timer1.Interval = 2000;
        textBox1.Select();
    }

    //test focus stuff
    //Spawns a new Thread.
    private void spawnThread(ThreadStart ts)
    {
        try
        {
            newThread = new Thread(ts);
            newThread.Start();
        }
        catch (Exception e)
        {
            MessageBox.Show(e.Message, "Exception!", MessageBoxButtons.OK,
                MessageBoxIcon.Error);
        }
    }

    //Continuously call getFocus.
    private void keepFocus()
    {
        while (true)
        {
            getFocus();
        }
    }

    //Keeps Form on top and gives …
Run Code Online (Sandbox Code Playgroud)

.net c# window winforms form-control

0
推荐指数
1
解决办法
9414
查看次数

Angular:有条件地改变 FormControl

我正在基于切换值创建表单组验证

public toggle:boolean=false;


ngOnInit(): void {
          this.formGroup = this.formBuilder.group({
          formArray: this.formBuilder.array([
            this.formBuilder.group({
              toggleFormCtrl: [this.toggle, null],
              fnameFormCtrl: ['', this.checkInputs.bind(this)],
              lnameFormCtrl: ['', this.checkInputs.bind(this)],
              addressFormCtrl: ['', this.checkMiInput.bind(this)]
            }),
         ])
       });

  }

checkInputs(c: FormControl) {
if (this.toggle) {
  return c.value === '' ? null : {
    checkinputs: {
      valid: false
    }
  };
} else {
  return c.value ? null : {
    checkinputs: {
      valid: false
    }
  };
}

}



checkMiInput(c: FormControl) {
    if (this.toggle) {
      return c.value ? null : {
        checkMiInput: {
          valid: …
Run Code Online (Sandbox Code Playgroud)

javascript typescript form-control angular angular4-forms

0
推荐指数
1
解决办法
4696
查看次数

React-Bootstrap FormControl 选择未显示值

import { Form } from 'react-bootstrap'

const nameArray = [
    {
        "id": 52655,
        "firstName": "raj",
        "lastName": "",
        "primaryAddress": "sad"
    },
    {
        "id": 52656,
        "firstName": "SubbaRaju",
        "lastName": "ch",
        "primaryAddress": "kphb"
    },
    {
        "id": 52667,
        "firstName": "Ravi",
        "lastName": "Varma",
        "primaryAddress": "Hyderabad"
    }
]

export default class File extends Component {
    constructor(props) {
        super(props);
        this.state = {
            object: {
                name: "",id:0
            }
        }
    }

    nameChange = (value) => {
        console.log(value)
        for(let i=0 ; i < nameArray.length; i++){
            if(value = nameArray[i].id){
                this.state.object.name = nameArray[i].firstName …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs form-control react-bootstrap

-1
推荐指数
1
解决办法
3120
查看次数

如何修复无法绑定到 formControl 错误

任何人都可以帮我解释为什么它说“无法绑定到'formControl',因为它不是'input'的已知属性。” 即使我已经导入了我的模块,并且我还有另一个使用 FormControl、FormGroup 或两者的组件,但它并没有给我带来这种错误,但这个却出现了。我不太确定为什么我一直收到此错误。

我已经在 app.module.ts 文件中导入了 ReactiveFormsModule 。我可以在其他组件中使用 formControl,但不确定为什么不能在此组件中使用。

超文本标记语言

<div class="component">
    <mat-chip-list *ngIf="editMode" #chipList >
         <div>
            <mat-chip> </mat-chip>
         <div>
            <div >
                <input matInput  #input  [formControl]="tagCtrl2"  [(ngModel)]="tagIn"  placeholder="Select or Create a tag" [matAutocomplete]="auto"
                    (focusout)="hideTagInput()" (keyup.enter)="addTag()"(keyup.escape)="hideTagInput()"
                    (keydown.backspace)="$event.stopPropagation();" (keydown.space)="$event.stopPropagation();" [matChipInputFor]="chipList" />
            </div>

            <mat-autocomplete #auto="matAutocomplete" (optionSelected)="selected($event)">
                <mat-option *ngFor="let tag of filteredTags | async" [value]="tag">
                    {{tag}}
                </mat-option>
            </mat-autocomplete>

    <mat-chip-list>
</div>
Run Code Online (Sandbox Code Playgroud)

TS

import { FormControl } from '@angular/forms';

export class TagsComponent implements OnInit {
   tagCtrl2 = new FormControl();
Run Code Online (Sandbox Code Playgroud)

html form-control angular-material angular

-1
推荐指数
1
解决办法
3541
查看次数