Requiring a checkbox to be checked

后端 未结 11 1865
猫巷女王i
猫巷女王i 2020-12-25 09:51

I want a button to be disabled until a checkbox has been checked using a FormBuilder for Angular. I don\'t want to explicitly check the value of the checkbox and would prefe

11条回答
  •  有刺的猬
    2020-12-25 10:19

    HTML Form

    Please agree to terms of use and privacy policy.

    TS File

      regForm: FormGroup;isRegSubmit: boolean = false;
      constructor(
        private fb: FormBuilder
      }
    
      this.regForm = this.fb.group({
            agree    : [false, Validators.requiredTrue]
        });
    

    Validators.required not worked Also, we can show error message by checking the value too and restrict the user to submit but it is not a good approach as we're not using validation, so whenever there is only a single checkbox then add Validators.requiredTrue instead of Validators.required

提交回复
热议问题