Topic: Validation for Radio buttons
Validation for the radio buttons in my reactive form is working correctly. When the form control is invalid, the red border and label appear as expected. However, after the user makes a selection and the control becomes valid, the green validation border shows up -but the selected radio button looks distorted. The green border becomes much thicker than the red one, and there’s no spacing between the border and the inner selected circle, making it look visually unappealing.
<div class="col-12 col-lg-6">
<div class="form-check form-check-inline">
<input
mdbRadio mdbValidate
class="form-check-input"
type="radio"
name="selectedOption"
id="optionNo"
formControlName="selectedOption"
[value]="'false'"
/>
<label class="form-check-label" for="optionNo">Option 1</label>
</div>
<div class="form-check form-check-inline">
<input
mdbRadio mdbValidate
class="form-check-input"
type="radio"
name="selectedOption"
id="optionYes"
formControlName="selectedOption"
[value]="'true'"
/>
<label class="form-check-label" for="optionYes">Option 2</label>
</div>
</div>
Question, is it possible to show red border and label for invalid control, but do not change style for valid one? If it is possible, could you please provide an example. Thank you.
Arkadiusz Idzikowski
staff answered 2 weeks ago
Looks like a bug, I added it to our to-do list.
As a workaround for now you can try to use those global styles (just add them to the styles.scss):
.form-check .form-check-input[type="radio"].validate-success.ng-valid.ng-dirty:checked,
.form-check .form-check-input[type="radio"].validate-success.ng-valid.ng-touched:checked {
border-color: #14a44d;
background-color: #fff;
}
.form-check .form-check-input[type="radio"].validate-success.ng-valid.ng-dirty:checked:after,
.form-check .form-check-input[type="radio"].validate-success.ng-valid.ng-touched:checked:after {
border-color: #14a44d;
background-color: #14a44d;
}
Or if you want to remove the success validation styles, use [validateSuccess]="false" input on any element with the mdbValidate directive.
<input
mdbRadio
mdbValidate
[validateSuccess]="false"
class="form-check-input"
type="radio"
name="selectedOption"
id="optionYes"
formControlName="selectedOption"
[value]="'true'"
/>
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Answered
- User: Pro
- Premium support: No
- Technology: MDB Angular
- MDB Version: MDB5 9.1.0
- Device: Laptop
- Browser: Chrome
- OS: W11
- Provided sample code: No
- Provided link: No