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
}
}
--
You received this message because you are subscribed to the Google Groups
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/angular/88a14ec1-9f49-4097-9ce2-77206b4e5a2fo%40googlegroups.com.