I am encountering an issue with form validation in Vue CLI and Bootstrap. When the page loads, all input fields show as invalid due to being assigned the is-invalid
class. I managed to solve this problem by setting the state prop to null when it is false. It seems unusual for the validation to run automatically when the page loads, even though I have followed the bootstrap-vue documentation carefully.
Here's a snippet of my code:
<b-form
@submit.prevent="addReview"
name="review-form"
class="needs-validation"
novalidate
>
<div class="name">
<label class="sr-only" for="form-input-name">Name</label>
<b-input
id="form-input-name"
class="form-inputs mb-2 mr-sm-2 mb-sm-0"
v-model="name"
placeholder="Name"
required
:state="isEmpty(this.name) ? true : null"
></b-input>
...
</b-form>
The issue arises from the ternary operator which needs three results - null on load to hide error messages, false to display errors on validation, and true to indicate valid input. After struggling with this for days, I would appreciate any help or suggestions regarding this setup. The submit button adds the class was-validated
but does not validate inputs properly.
Question:
How can I validate inputs without displaying error messages on page load?