Search code examples
vue.jsvuelidate

Vuelidate - shaking the incorrect input field


Take a look at Basic form at Vuelidate documentation. If the rule is broken (text is too short), the label is red, then eror message appears and the input field shakes for a while. How is this done? I have copied the source code sample and the shaking effect is not there. I cannot even simulate it with an official fiddle: https://jsfiddle.net/so89zmpe/2/

<div class="form-group" :class="{ 'form-group--error': $v.name.$error }">
  <label class="form__label">Name</label>
  <input class="form__input" v-model.trim="$v.name.$model"/>
</div>

I cannot find anything relevant in Chrome developer enter image description here


Solution

  • If you open DevTools > Animations tab, you can see that there's an animation name of shakeError applied on .form-group.form-group--error:

    enter image description here

    Here's the definition of shakeError:

    @keyframes shakeError {
      0% {
        transform: translateX(0); }
      15% {
        transform: translateX(0.375rem); }
      30% {
        transform: translateX(-0.375rem); }
      45% {
        transform: translateX(0.375rem); }
      60% {
        transform: translateX(-0.375rem); }
      75% {
        transform: translateX(0.375rem); }
      90% {
        transform: translateX(-0.375rem); }
      100% {
        transform: translateX(0); } }
    

    And then,

    .form-group--alert,
    .form-group--error {
      animation-name: shakeError;
      animation-fill-mode: forwards;
      animation-duration: .6s;
      animation-timing-function: ease-in-out; }
    

    You can check the Sources tab of https://vuelidate.js.org/#sub-basic-form for a docs.scss file to dig in deeper.