I have modal i.e ngx-bootstrap modal in which there are two radio buttons.
I want to get a shake effect on the selected radio button as validation in case the 'Next' button is clicked.
I have already created css class for the shake effect. I want to add this css click on clicking on the button when the it is required. I tried using ngClass but it is not working as expected. How this can be done?
HTML
<ng-template #myModal>
<div class="modal-body">
<div class="row">
<div class="col-md-4 col-md-offset-3 text-center">
<input formControlName="genderName" type="radio" id="female" value="Female" [ngClass]="{'rederror': this.cf.genderName.required}">
<label for="female" class="female">Female</label>
</div>
<div class="col-md-4 col-md-pull-1 ml-4">
<input formControlName="genderName" type="radio" id="male" value="Male" [ngClass]="{'rederror': this.cf.genderName.required}">
<label for="male" class="male">Male</label>
</div>
<button type="button" (click)="submit()">Next</button>
</div>
</div>
</ng-template>
css file
input[type=radio].rederror {
animation: shake 0.5s 3 linear;
border: 1px solid red;
}
@keyframes shake {
0% {margin-left: 0;}
25% {margin-left: 0.5rem;}
75% {margin-left: -0.5rem;}
100% {margin-left: 0;}
}