Looking for assistance with form validation using Radio elements on a Bootstrap 4 page.
I want to display an error message underneath the radio element:
<div class="invalid-feedback">Please choose an option</div>
Below is the code snippet within my form:
<section>
<h6>Lorem Ipsum</h6>
<p>Donec molestie orci rhoncus, congue magna facilisis, laoreet sapien. Nam.</p>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="agreeMarketProfiling" id="agreeMarketProfiling1" value="1" required>
<label class="form-check-label" for="agreeMarketProfiling1">I AGREE</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="agreeMarketProfiling" id="agreeMarketProfiling2" value="0" required>
<label class="form-check-label" for="agreeMarketProfiling2">DON'T AGREE</label>
</div>
</section>
When placing the invalid-feedback
inside the form-check
element, the error message appears below the single element. When it's placed outside the form-check
element, the error message doesn't show up.
What's the correct way to achieve this?