Angular 4 remove required validator conditionally

Discussão em 'Angular' iniciado por Ali Shahzad, Março 1, 2025.

  1. Ali Shahzad

    Ali Shahzad Guest

    In Angular 4 app I have a form model like this:

    this.form = this._fb.group({
    title: ['', [Validators.required, Validators.minLength(3), Validators.maxLength(50)]],
    description: ['', [Validators.required, Validators.minLength(3)]]
    });


    Now what I want is to remove dynamically only the required validator from the control validators array. Something like this:

    saveDraft() {
    this.form.controls['title'].removeValidator('required'); //Just a fake implementation for demonstration
    }


    This question is not the duplicate of the mentioned question. My case is different I just want to remove the required validator unknowingly the other ones.

    Continue reading...

Compartilhe esta Página