Vue Bootstrap Validation

Vue Validation - Bootstrap 4 & Material Design

Note: This documentation is for an older version of Bootstrap (v.4). A newer version is available for Bootstrap 5. We recommend migrating to the latest version of our product - Material Design for Bootstrap 5.
Go to docs v.5

Provide valuable, actionable feedback to your users with HTML5 form validation – available in all our supported browsers. Choose from the browser default validation feedback, or implement custom messages with our built-in classes and starter JavaScript.

Warning

We currently recommend using custom validation styles, as native browser default validation messages are not consistently exposed to assistive technologies in all browsers (most notably, Chrome on desktop and mobile).


How it works

Here’s how form validation works with Bootstrap:

  • HTML form validation is applied via CSS’s two pseudo-classes, :invalid and :valid. It applies to <input>, <select>, and <textarea> elements.
  • Bootstrap scopes the :invalid and :valid styles to parent .was-validated class, usually applied to the <form>. Otherwise, any required field without a value shows up as invalid on page load. This way, you may choose when to activate them (typically after form submission is attempted).
  • To reset the appearance of the form (for instance, in the case of dynamic form submissions using AJAX), remove the .was-validated class from the <form> again after submission.
  • As a fallback, .is-invalid and .is-valid classes may be used instead of the pseudo-classes for server side validation. They do not require a .was-validated parent class.
  • Due to constraints in how CSS works, we cannot (at present) apply styles to a <label> that comes before a form control in the DOM without the help of custom JavaScript.
  • All modern browsers support the constraint validation API, a series of JavaScript methods for validating form controls.
  • Feedback messages may utilize the browser defaults (different for each browser, and unstylable via CSS) or our custom feedback styles with additional HTML and CSS.
  • You may provide custom validity messages with setCustomValidity in JavaScript.

With that in mind, consider the following demos for our custom form validation styles, optional server side classes, and browser defaults.


Custom styles

For custom Bootstrap form validation messages, you’ll need to add the novalidate boolean attribute to your <form>. This disables the browser default feedback tooltips, but still provides access to the form validation APIs in JavaScript. Try to submit the form below; our JavaScript will intercept the submit button and relay feedback to you.

When attempting to submit, you’ll see the :invalid and :valid styles applied to your form controls.

Default styles

Looks good!
Looks good!
@
Please choose a username.
Please provide a valid city.
Please provide a valid state.
Please provide a valid zip.
You must agree before submitting.

              <template>
                <mdb-container class="mt-5">
                  <h1 class="my-5">Form Validation</h1>
                  <!-- Custom styles -->
                  <h2 class="my-5">Custom styles</h2>
                  <form class="needs-validation" novalidate @submit="checkForm">
                    <div class="form-row">
                      <div class="col-md-4 mb-3">
                        <label for="validationCustom01">First name</label>
                        <input type="text" class="form-control" id="validationCustom01" placeholder="First name" value="Mark" required>
                        <div class="valid-feedback">
                          Looks good!
                        </div>
                      </div>
                      <div class="col-md-4 mb-3">
                        <label for="validationCustom02">Last name</label>
                        <input type="text" class="form-control" id="validationCustom02" placeholder="Last name" value="Otto" required>
                        <div class="valid-feedback">
                          Looks good!
                        </div>
                      </div>
                      <div class="col-md-4 mb-3">
                        <label for="validationCustomUsername">Username</label>
                        <div class="input-group">
                          <div class="input-group-prepend">
                            <span class="input-group-text" id="inputGroupPrepend">@</span>
                          </div>
                          <input type="text" class="form-control" id="validationCustomUsername" placeholder="Username" aria-describedby="inputGroupPrepend" required>
                          <div class="invalid-feedback">
                            Please choose a username.
                          </div>
                        </div>
                      </div>
                    </div>
                    <div class="form-row">
                      <div class="col-md-6 mb-3">
                        <label for="validationCustom03">City</label>
                        <input type="text" class="form-control" id="validationCustom03" placeholder="City" required>
                        <div class="invalid-feedback">
                          Please provide a valid city.
                        </div>
                      </div>
                      <div class="col-md-3 mb-3">
                        <label for="validationCustom04">State</label>
                        <input type="text" class="form-control" id="validationCustom04" placeholder="State" required>
                        <div class="invalid-feedback">
                          Please provide a valid state.
                        </div>
                      </div>
                      <div class="col-md-3 mb-3">
                        <label for="validationCustom05">Zip</label>
                        <input type="text" class="form-control" id="validationCustom05" placeholder="Zip" required>
                        <div class="invalid-feedback">
                          Please provide a valid zip.
                        </div>
                      </div>
                    </div>
                    <div class="form-group">
                      <div class="form-check pl-0">
                        <input class="form-check-input" type="checkbox" value="" id="invalidCheck" required>
                        <label class="form-check-label" for="invalidCheck">
                          Agree to terms and conditions
                        </label>
                        <div class="invalid-feedback">
                          You must agree before submitting.
                        </div>
                      </div>
                    </div>
                    <mdb-btn type="submit">Submit form</mdb-btn>
                  </form>
                </mdb-container>
              </template>
            

              <script>
                import { mdbContainer, mdbBtn } from "mdbvue";
                export default {
                  name: "InputsPage",
                  components: {
                    mdbContainer,
                    mdbBtn
                  },
                  methods: {
                    checkForm(event) {
                      event.preventDefault();
                      event.target.classList.add('was-validated');
                    }
                  }
                }
              </script>
            

Material styles MDB Pro component

Looks good!
Looks good!
Please choose a username.
Please provide a valid city.
Please provide a valid state.
Please provide a valid zip.
You must agree before submitting.


              <template>
                <form novalidate @submit.prevent="checkForm">
                  <div class="form-row">
                    <div class="col-md-4">
                      <mdb-input type="text" id="validationCustom10" placeholder="First name" label="First name" value="Mark" required validFeedback="Look's good." />
                    </div>
                    <div class="col-md-4">
                      <mdb-input type="text" id="validationCustom11" placeholder="Last name" label="Last name" value="Otto" required validFeedback="Look's good." />
                    </div>
                    <div class="col-md-4">
                      <mdb-input type="text" id="validationCustom12" placeholder="Username" label="Username" required invalidFeedback="Please choose a username." />
                    </div>
                  </div>
                  <div class="form-row">
                    <div class="col-md-6">
                      <mdb-input type="text" id="validationCustom13" placeholder="City" label="City" required invalidFeedback="Please provide a valid city." />
                    </div>
                    <div class="col-md-3">
                      <mdb-input type="text" id="validationCustom14" placeholder="State" label="State" required invalidFeedback="Please provide a valid state." />
                    </div>
                    <div class="col-md-3">
                      <mdb-input type="text" id="validationCustom15" placeholder="Zip" label="Zip" required invalidFeedback="Please provide a valid zip." />
                    </div>
                  </div>
                  <div class="form-group">
                    <mdb-input type="checkbox" class="pl-0" id="invalidCheck" label="Agree to terms and conditions" required invalidFeedback="You must agree before submitting." />
                  </div>
                  <mdb-btn type="submit">Submit form</mdb-btn>
                </form>
              </template>

            


              <script>
                import { mdbContainer, mdbBtn, mdbIcon, mdbRow, mdbCol, mdbInput } from "mdbvue";

                export default {
                  name: "ValidationPagePro",
                  components: {
                    mdbContainer,
                    mdbBtn,
                    mdbIcon,
                    mdbRow,
                    mdbCol,
                    mdbInput
                  },
                  methods: {
                    checkForm(event) {
                      event.target.classList.add('was-validated');
                    }
                  }
                };

              </script>

            

Browser defaults

Not interested in custom validation feedback messages or writing JavaScript to change form behaviors? All good, you can use the browser defaults. Try submitting the form below. Depending on your browser and OS, you’ll see a slightly different style of feedback.

While these feedback styles cannot be styled with CSS, you can still customize the feedback text through JavaScript.

Default styles

@

                <template>
                  <mdb-container class="mt-5">
                    <form>
                      <div class="form-row">
                        <div class="col-md-4 mb-3">
                          <label for="validationCustom01">First name</label>
                          <input type="text" class="form-control" id="validationCustom01" placeholder="First name" value="Mark" required>
                        </div>
                        <div class="col-md-4 mb-3">
                          <label for="validationCustom02">Last name</label>
                          <input type="text" class="form-control" id="validationCustom02" placeholder="Last name" value="Otto" required>
                        </div>
                        <div class="col-md-4 mb-3">
                          <label for="validationCustomUsername">Username</label>
                          <div class="input-group">
                            <div class="input-group-prepend">
                              <span class="input-group-text" id="inputGroupPrepend">@</span>
                            </div>
                            <input type="text" class="form-control" id="validationCustomUsername" placeholder="Username" aria-describedby="inputGroupPrepend" required>
                          </div>
                        </div>
                      </div>
                      <div class="form-row">
                        <div class="col-md-6 mb-3">
                          <label for="validationCustom03">City</label>
                          <input type="text" class="form-control" id="validationCustom03" placeholder="City" required>
                        </div>
                        <div class="col-md-3 mb-3">
                          <label for="validationCustom04">State</label>
                          <input type="text" class="form-control" id="validationCustom04" placeholder="State" required>
                        </div>
                        <div class="col-md-3 mb-3">
                          <label for="validationCustom05">Zip</label>
                          <input type="text" class="form-control" id="validationCustom05" placeholder="Zip" required>
                        </div>
                      </div>
                      <div class="form-group">
                        <div class="form-check pl-0">
                          <input class="form-check-input" type="checkbox" value="" id="invalidCheck" required>
                          <label class="form-check-label" for="invalidCheck">
                            Agree to terms and conditions
                          </label>
                        </div>
                      </div>
                      <mdb-btn type="submit">Submit form</mdb-btn>
                    </form>
                  </mdb-container>
                </template>
              

                <script>
                  import { mdbContainer, mdbBtn } from "mdbvue";
                  export default {
                    name: "InputsPage",
                    components: {
                      mdbContainer,
                      mdbBtn
                    }
                  }
                </script>
              

Material stylesMDB Pro component


                  <template>
                    <form>
                      <div class="form-row">
                        <div class="col-md-4">
                          <mdb-input type="text" id="validationCustom1" placeholder="First name" label="First name" value="Mark" required validFeedback="Look's good." />
                        </div>
                        <div class="col-md-4">
                          <mdb-input type="text" id="validationCustom2" placeholder="Last name" label="Last name" value="Otto" required validFeedback="Look's good." />
                        </div>
                        <div class="col-md-4">
                          <mdb-input type="text" id="validationCustom3" placeholder="Username" label="Username" required invalidFeedback="Please choose a username." />
                        </div>
                      </div>
                      <div class="form-row">
                        <div class="col-md-6">
                          <mdb-input type="text" id="validationCustom4" placeholder="City" label="City" required invalidFeedback="Please provide a valid city." />
                        </div>
                        <div class="col-md-3">
                          <mdb-input type="text" id="validationCustom5" placeholder="State" label="State" required invalidFeedback="Please provide a valid state." />
                        </div>
                        <div class="col-md-3">
                          <mdb-input type="text" id="validationCustom6" placeholder="Zip" label="Zip" required invalidFeedback="Please provide a valid zip." />
                        </div>
                      </div>
                      <div class="form-group">
                        <mdb-input type="checkbox" class="pl-0" id="invalidCheck2" label="Agree to terms and conditions" required invalidFeedback="You must agree before submitting." />
                      </div>
                      <mdb-btn type="submit">Submit form</mdb-btn>
                    </form>
                  </template>
                

                  <script>
                    import { mdbContainer, mdbBtn, mdbIcon, mdbRow, mdbCol, mdbInput } from "mdbvue";

                    export default {
                      name: "ValidationPagePro",
                      components: {
                        mdbContainer,
                        mdbBtn,
                        mdbIcon,
                        mdbRow,
                        mdbCol,
                        mdbInput
                      }
                    };
                  </script>
                

Server side

We recommend using client side validation, but in case you require server side, you can indicate invalid and valid form fields with .is-invalid and .is-valid. Note that .invalid-feedback is also supported with these classes.

Default styles

Looks good!
Looks good!
@
Please choose a username.
Please provide a valid city.
Please provide a valid state.
Please provide a valid zip.
You must agree before submitting.
You must agree before submitting.

              <template>
                <mdb-container class="mt-5">
                  <form class="needs-validation" novalidate @submit="checkForm">
                    <div class="form-row">
                      <div class="col-md-4 mb-3">
                        <label for="validationCustom01">First name</label>
                        <input type="text" class="form-control is-valid" id="validationCustom01" placeholder="First name" value="Mark" required>
                        <div class="valid-feedback">
                          Looks good!
                        </div>
                      </div>
                      <div class="col-md-4 mb-3">
                        <label for="validationCustom02">Last name</label>
                        <input type="text" class="form-control is-valid" id="validationCustom02" placeholder="Last name" value="Otto" required>
                        <div class="valid-feedback">
                          Looks good!
                        </div>
                      </div>
                      <div class="col-md-4 mb-3">
                        <label for="validationCustomUsername">Username</label>
                        <div class="input-group">
                          <div class="input-group-prepend">
                            <span class="input-group-text" id="inputGroupPrepend">@</span>
                          </div>
                          <input type="text" class="form-control is-invalid" id="validationCustomUsername" placeholder="Username" aria-describedby="inputGroupPrepend" required>
                          <div class="invalid-feedback">
                            Please choose a username.
                          </div>
                        </div>
                      </div>
                    </div>
                    <div class="form-row">
                      <div class="col-md-6 mb-3">
                        <label for="validationCustom03">City</label>
                        <input type="text" class="form-control is-invalid" id="validationCustom03" placeholder="City" required>
                        <div class="invalid-feedback">
                          Please provide a valid city.
                        </div>
                      </div>
                      <div class="col-md-3 mb-3">
                        <label for="validationCustom04">State</label>
                        <input type="text" class="form-control is-invalid" id="validationCustom04" placeholder="State" required>
                        <div class="invalid-feedback">
                          Please provide a valid state.
                        </div>
                      </div>
                      <div class="col-md-3 mb-3">
                        <label for="validationCustom05">Zip</label>
                        <input type="text" class="form-control is-invalid" id="validationCustom05" placeholder="Zip" required>
                        <div class="invalid-feedback">
                          Please provide a valid zip.
                        </div>
                      </div>
                    </div>
                    <div class="form-group">
                      <div class="form-check pl-0">
                        <input class="form-check-input is-invalid" type="checkbox" value="" id="invalidCheck" required>
                        <label class="form-check-label" for="invalidCheck">
                          Agree to terms and conditions
                        </label>
                        <div class="invalid-feedback">
                          You must agree before submitting.
                        </div>
                      </div>
                    </div>
                    <mdb-btn type="submit">Submit form</mdb-btn>
                  </form>
                </mdb-container>
              </template>
            

              <script>
                import { mdbContainer, mdbBtn } from "mdbvue";
                export default {
                  name: "InputsPage",
                  components: {
                    mdbContainer,
                    mdbBtn
                  },
                  methods: {
                    checkForm(event) {
                      event.preventDefault();
                      event.target.classList.add('was-validated');
                    }
                  }
                }
              </script>
            

Material styles

Looks good!
Looks good!
Please choose a username.
Please provide a valid city.
Please provide a valid state.
Please provide a valid zip.
You must agree before submitting.

              <template>
                <form class="was-validated" novalidate>
                  <div class="form-row">
                    <div class="col-md-4">
                      <mdb-input type="text" id="validationCustom21" placeholder="First name" label="First name" value="Mark" required
                        validFeedback="Look's good." />
                    </div>
                    <div class="col-md-4">
                      <mdb-input type="text" id="validationCustom22" placeholder="Last name" label="Last name" value="Otto" required
                        validFeedback="Look's good." />
                    </div>
                    <div class="col-md-4">
                      <mdb-input type="text" id="validationCustom23" placeholder="Username" label="Username" required
                        invalidFeedback="Please choose a username." />
                    </div>
                  </div>
                  <div class="form-row">
                    <div class="col-md-6">
                      <mdb-input type="text" id="validationCustom24" placeholder="City" label="City" required
                        invalidFeedback="Please provide a valid city." />
                    </div>
                    <div class="col-md-3">
                      <mdb-input type="text" id="validationCustom25" placeholder="State" label="State" required
                        invalidFeedback="Please provide a valid state." />
                    </div>
                    <div class="col-md-3">
                      <mdb-input type="text" id="validationCustom26" placeholder="Zip" label="Zip" required
                        invalidFeedback="Please provide a valid zip." />
                    </div>
                  </div>
                  <div class="form-group">
                    <mdb-input type="checkbox" class="pl-0" id="invalidCheck22" label="Agree to terms and conditions" required
                      invalidFeedback="You must agree before submitting." />
                  </div>
                  <mdb-btn type="submit">Submit form</mdb-btn>
                </form>
              </template>
            

              <script>
                import { mdbContainer, mdbBtn, mdbIcon, mdbRow, mdbCol, mdbInput } from "mdbvue";

                export default {
                  name: "ValidationPagePro",
                  components: {
                    mdbContainer,
                    mdbBtn,
                    mdbIcon,
                    mdbRow,
                    mdbCol,
                    mdbInput
                  }
                };
              </script>
            

Supported elements

Our example forms show native textual <input>s above, but form validation styles are available for our custom form controls, too.

Default styles

Example invalid feedback text
More example invalid feedback text
Example invalid custom select feedback
Example invalid custom file feedback

                <template>
                  <mdb-container class="mt-5">
                    <!-- Supported elements -->
                    <hr class="my-5">
                    <h2 class="my-5">Supported elements</h2>
                    <form class="was-validated">
                      <div class="custom-control custom-checkbox mb-3">
                        <input type="checkbox" class="custom-control-input" id="customControlValidation1" required>
                        <label class="custom-control-label" for="customControlValidation1">Check this custom checkbox</label>
                        <div class="invalid-feedback">Example invalid feedback text</div>
                      </div>

                      <div class="custom-control custom-radio">
                        <input type="radio" class="custom-control-input" id="customControlValidation2" name="radio-stacked" required>
                        <label class="custom-control-label" for="customControlValidation2">Toggle this custom radio</label>
                      </div>
                      <div class="custom-control custom-radio mb-3">
                        <input type="radio" class="custom-control-input" id="customControlValidation3" name="radio-stacked" required>
                        <label class="custom-control-label" for="customControlValidation3">Or toggle this other custom radio</label>
                        <div class="invalid-feedback">More example invalid feedback text</div>
                      </div>

                      <div class="form-group">
                        <select class="custom-select browser-default" required>
                          <option value="">Open this select menu</option>
                          <option value="1">One</option>
                          <option value="2">Two</option>
                          <option value="3">Three</option>
                        </select>
                        <div class="invalid-feedback">Example invalid custom select feedback</div>
                      </div>
                      <div class="custom-file">
                        <input type="file" class="custom-file-input" id="validatedCustomFile" required>
                        <label class="custom-file-label" for="validatedCustomFile">Choose file...</label>
                        <div class="invalid-feedback">Example invalid custom file feedback</div>
                      </div>
                    </form>
                  </mdb-container>
                </template>
              

                <script>
                  import { mdbContainer } from "mdbvue";
                  export default {
                    name: "InputsPage",
                    components: {
                      mdbContainer
                    },
                    methods: {
                      checkForm(event) {
                        event.preventDefault();
                        event.target.classList.add('was-validated');
                      }
                    }
                  }
                </script>
              

Material styles MDB Pro component

Example invalid feedback text
More example invalid feedback text
Choose file
Example invalid custom file feedback

                <template>
                  <form class="was-validated">
                    <mdb-input type="checkbox" id="customControlValidation31" required label="Check this custom checkbox"
                      invalidFeedback="Example invalid feedback text" />
                    <mdb-input type="radio" class="mt-3" id="option1-1" name="option1" label="Toggle this material radio" required />
                    <mdb-input type="radio" id="option1-2" name="option1" label="Or toggle this other material radio" required
                      invalidFeedback="Example invalid feedback text" />
                    <mdb-file-input btnColor="primary" />
                  </form>
                </template>
              

                <script>
                import { mdbInput, mdbFileInput } from "mdbvue";

                export default {
                  name: "ValidationPagePro",
                  components: {
                    mdbInput,
                    mdbFileInput
                  }
                };
                </script>
              

Tooltips

If your form layout allows it, you can swap the .{valid|invalid}-feedback classes for .{valid|invalid}-tooltip classes to display validation feedback in a styled tooltip. Be sure to have a parent with position: relative on it for tooltip positioning. In the example below, our column classes have this already, but your project may require an alternative setup.

Looks good!
Looks good!
@
Please choose a unique and valid username.
Please provide a valid city.
Please provide a valid state.
Please provide a valid zip.

          <template>
            <mdb-container class="mt-5">
              <!-- Tooltips -->
              <hr class="my-5">
              <h2 class="my-5">Tooltips</h2>
              <form class="needs-validation" novalidate @submit="checkForm">
                <div class="form-row">
                  <div class="col-md-4 mb-3">
                    <label for="validationTooltip01">First name</label>
                    <input type="text" class="form-control" id="validationTooltip01" placeholder="First name" value="Mark" required>
                    <div class="valid-tooltip">
                      Looks good!
                    </div>
                  </div>
                  <div class="col-md-4 mb-3">
                    <label for="validationTooltip02">Last name</label>
                    <input type="text" class="form-control" id="validationTooltip02" placeholder="Last name" value="Otto" required>
                    <div class="valid-tooltip">
                      Looks good!
                    </div>
                  </div>
                  <div class="col-md-4 mb-3">
                    <label for="validationTooltipUsername">Username</label>
                    <div class="input-group">
                      <div class="input-group-prepend">
                        <span class="input-group-text" id="validationTooltipUsernamePrepend">@</span>
                      </div>
                      <input type="text" class="form-control" id="validationTooltipUsername" placeholder="Username" aria-describedby="validationTooltipUsernamePrepend" required>
                      <div class="invalid-tooltip">
                        Please choose a unique and valid username.
                      </div>
                    </div>
                  </div>
                </div>
                <div class="form-row">
                  <div class="col-md-6 mb-3">
                    <label for="validationTooltip03">City</label>
                    <input type="text" class="form-control" id="validationTooltip03" placeholder="City" required>
                    <div class="invalid-tooltip">
                      Please provide a valid city.
                    </div>
                  </div>
                  <div class="col-md-3 mb-3">
                    <label for="validationTooltip04">State</label>
                    <input type="text" class="form-control" id="validationTooltip04" placeholder="State" required>
                    <div class="invalid-tooltip">
                      Please provide a valid state.
                    </div>
                  </div>
                  <div class="col-md-3 mb-3">
                    <label for="validationTooltip05">Zip</label>
                    <input type="text" class="form-control" id="validationTooltip05" placeholder="Zip" required>
                    <div class="invalid-tooltip">
                      Please provide a valid zip.
                    </div>
                  </div>
                </div>
                <mdb-btn type="submit">Submit form</mdb-btn>
              </form>
            </mdb-container>
          </template>
        

          <script>
          import { mdbContainer, mdbBtn } from "mdbvue";
          export default {
            name: "InputsPage",
            components: {
              mdbContainer,
              mdbBtn
            },
            methods: {
              checkForm(event) {
                event.preventDefault();
                event.target.classList.add('was-validated');
              }
            }
          }
          </script>
        

Material Select Validation MDB Pro component"

Please select a country.
You shall not pass!

        <template>
          <mdb-row>
            <mdb-col sm="6">
              <mdb-select v-model="validateOptions" validation ref="validationSelect" resetBtn label="validate"/>
              <mdb-btn size="sm" color="primary" @click.native="$refs.validationSelect.validate()">Validate</mdb-btn>
            </mdb-col>
          </mdb-row>
        </template>
      

        <script>
          import { mdbBtn, mdbRow, mdbCol, mdbSelect } from "mdbvue";

          export default {
            name: "ValidationPagePro",
            components: {
              mdbBtn,
              mdbRow,
              mdbCol,
              mdbSelect
            },
            data() {
              return {
                validateOptions: [
                  { text: 'Option nr 1', value: 'Option 1' },
                  { text: 'Option nr 2', value: 'Option 2' },
                  { text: 'Option nr 3', value: 'Option 3' },
                  { text: 'Option nr 4', value: 'Option 4' },
                  { text: 'Option nr 5', value: 'Option 5' }
                ]
              };
            }
          };
        </script>
      

Custom validation MDB Pro component

Here's an example code of custom validation. It could be helpful if You want to apply multiple conditions to Your form inputs.


        <template>
          <form @submit.prevent="validateForm" novalidate>
            <mdb-input
              type="text"
              id="customInput1"
              label="First name"
              v-model="customValues.name"
              :customValidation="validation.name.validated"
              :isValid="validation.name.valid"
              @change="validate('name')"
              required
              validFeedback="Look's good."
              invalidFeedback="Please correct."
            />
            <mdb-input
              type="text"
              id="customInput2"
              label="Last name"
              v-model="customValues.lastname"
              :customValidation="validation.lastname.validated"
              :isValid="validation.lastname.valid"
              @change="validate('lastname')"
              required
              validFeedback="Look's good."
              invalidFeedback="Please correct."
            />
            <mdb-input
              type="text"
              id="customInput3"
              label="Country"
              v-model="customValues.country"
              :customValidation="validation.country.validated"
              :isValid="validation.country.valid"
              @change="validate('country')"
              required
              validFeedback="Look's good."
              invalidFeedback="Country should be one of those: USA, France, Poland"
            />
            <mdb-row>
              <mdb-col>
                <mdb-select
                  v-model="city"
                  validation
                  @change="validate('city')"
                  ref="select"
                  validFeedback="Look's good."
                  invalidFeedback="Please choose Your city."
                  label="City"
                  placeholder="Choose your city"
                />
              </mdb-col>
            </mdb-row>
            <mdb-input
              type="password"
              id="customInput4"
              label="Password"
              v-model="customValues.password"
              :customValidation="validation.password.validated"
              :isValid="validation.password.valid"
              @change="validate('password')"
              required
              validFeedback="Look's good."
              :invalidFeedback="validation.password.invalidFeedback"
            />
            <mdb-input
              class="pl-0 mb-3"
              type="checkbox"
              id="customInput5"
              v-model="customValues.checkbox"
              :customValidation="validation.checkbox.validated"
              :isValid="validation.checkbox.valid"
              @change="validate('checkbox')"
              required
              label="Check this custom checkbox"
              validFeedback="Correct"
              invalidFeedback="Please check me"
            />
            <mdb-btn type="Submit" size="sm" color="danger">Submit</mdb-btn>
          </form>
        </template>
      

        <script>
          import { mdbBtn, mdbRow, mdbCol, mdbInput, mdbSelect } from "mdbvue";

          export default {
            name: "ValidationPagePro",
            components: {
              mdbBtn,
              mdbRow,
              mdbCol,
              mdbInput,
              mdbSelect
            },
            data() {
              return {
                customValues: {
                  name: "Matt",
                  lastname: "Doe",
                  country: "",
                  city: "",
                  password: "",
                  checkbox: false,
                  datepicker: ""
                },

                validation: {
                  name: {
                    valid: false,
                    validated: false
                  },
                  lastname: {
                    valid: false,
                    validated: false
                  },
                  country: {
                    valid: false,
                    validated: false
                  },
                  city: {
                    valid: false,
                    validated: false
                  },
                  password: {
                    valid: false,
                    validated: false,
                    invalidFeedback: ''
                  },
                  checkbox: {
                    valid: false,
                    validated: false
                  }
                }
              };
            },
            computed: {
              city() {
                if (this.customValues.country === 'USA') {
                  return [
                    { text: 'Boston', value: 'boston' },
                    { text: 'Chicago', value: 'chicago' },
                    { text: 'New York', value: 'newYork' }
                  ];
                } else if (this.customValues.country === 'France') {
                  return [
                    { text: 'Paris', value: 'paris' },
                    { text: 'Nantes', value: 'nantes' },
                    { text: 'Lyon', value: 'lyon' }
                  ];
                } else if (this.customValues.country === 'Poland') {
                  return [
                    { text: 'Warszawa', value: 'warszawa' },
                    { text: 'Kraków', value: 'krakow' },
                    { text: 'Gdańsk', value: 'gdansk' },
                  ];
                }
                return [
                ];
              }
            },
            methods: {
              validateForm() {
                Object.keys(this.customValues).forEach(key => {
                  this.validate(key);
                });
              },
              validate(key, value) {
                if (key === "name" || key === "lastname" || key === "checkbox") {
                  if (this.customValues[key]) {
                    this.validation[key].valid = true;
                  } else {
                    this.validation[key].valid = false;
                  }
                  this.validation[key].validated = true;
                }
                if (key === "country") {
                  if (["USA", "France", "Poland"].includes(this.customValues[key])) {
                    this.validation[key].valid = true;
                  } else {
                    this.validation[key].valid = false;
                  }
                  this.validation[key].validated = true;
                }
                if (key === "password") {
                  // check length
                  if (this.customValues[key].length > 5) {
                    // check uppercase
                    for (let character of this.customValues[key].split("")) {
                      if (character === character.toUpperCase()) {
                        this.validation[key].valid = true;
                        break;
                      }
                      this.validation[key].valid = false;
                      this.validation[key].invalidFeedback =
                        "Password should contain at least one uppercase character.";
                    }
                  } else {
                    this.validation[key].valid = false;
                    this.validation[key].invalidFeedback =
                      "Password too short. Type at least 6 letters.";
                  }
                  this.validation[key].validated = true;
                }
                if (key === "city") {

                  this.$refs.select.validate();
                }
                if (key === "arrival") {
                  if (value) {
                    this.validation[key].valid = true;
                  } else {
                    this.validation[key].valid = false;
                  }
                  this.validation[key].validated = true;
                }
              },
            }
          };
        </script>