I have created a star rating user interface using the Bootstrap 4 .btn-group.btn-group-toggle
as shown in the code snippet below:
<div class="form-group">
<div class="btn-group btn-group-toggle" data-toggle="buttons" aria-label="Rate this">
<label class="btn btn-dark btn-sm">
<input type="radio" name="rating" value="1" required> 1
</label>
<label class="btn btn-dark btn-sm">
<input type="radio" name="rating" value="2" required> 2
</label>
<label class="btn btn-dark btn-sm">
<input type="radio" name="rating" value="3" required> 3
</label>
<label class="btn btn-dark btn-sm">
<input type="radio" name="rating" value="4" required> 4
</label>
<label class="btn btn-dark btn-sm">
<input type="radio" name="rating" value="5" required> 5
</label>
</div>
<div class="invalid-feedback">
Please rate the item on a scale of 5
</div>
</div>
Unfortunately, the validation error is not visible when a rating is not provided. I am utilizing the HTML5 default validation method suggested by Bootstrap 4 and implemented with JavaScript.
Is there a way to display a validation error for the .btn-group-toggle
element?