Help needed in Radio Button validation

7 views
Skip to first unread message

option donna

unread,
Aug 11, 2020, 12:21:53 AM8/11/20
to Angular and AngularJS discussion
Hello, 

i am new to angular and my current office project is in angular 6. i need to validate the radio button on button click. below is the code. but its not working. any help will be highly appreciated



<fieldset class="opt-out-prompt">
        <span *ngIf="editMode==='del'>
          <p>months you don't need this order?</p>
          <input type="radio" formControlName="actionType"  name="actionType" role="radiogroup" id="deleteorder">
          <label for="deleteorder"> No, please delete my order altogether</label>
          <br>
          <input type="radio" formControlName="actionType" name="actionType" role="radiogroup" id="optoutmonth" >
          <label for="optoutmonth"> Yes, show me opt-out months</label>
        </span>
        <div *ngIf="submittedOnce && cartForm.errors?.required">
          <p>Please select either value</p>
       </div>
      </fieldset>


.TS Code :


CartOptionForm = this.fb.group({
    actionType: ['', [Validators.required]]
  })
  get cartForm() {
    return this.CartOptionForm.get('actionType');
  }

 onSubmit() {
    this.submittedOnce = true;
    
    if (this.isFormValid()) {
       // success
    }
  }

isFormValid(): boolean {
    
    if(!this.CartOptionForm.valid) {
      return false;
    }
 else
{
 
    return true
}
}




Reply all
Reply to author
Forward
0 new messages