npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@privyid/vuelidate-penak

v1.0.0

Published

Vuelidate Penak is a tool that makes it even easier to display error messages in your Vue.js forms when using the Vuelidate library. With Vuelidate Penak, you can quickly and easily create and customize error messages for your form inputs, without having

Downloads

1

Readme

Vuelidate Penak 🔥

Vuelidate Penak is a tool that makes it even easier to display error messages in your Vue.js forms when using the Vuelidate library. With Vuelidate Penak, you can quickly and easily create and customize error messages for your form inputs, without having to write any complex validation logic yourself. This makes it a great option for developers who want to add powerful form validation to their Vue.js applications, without having to spend a lot of time and effort on the implementation. Overall, Vuelidate Penak makes error message display from Vuelidate a breeze, allowing you to quickly and easily create user-friendly forms that are easy to use and maintain.

Table Of Content 📖

Installation 🚀

npm i @privyid/vuelidate-penak

Usage ✨

Global Usage

import VuelidatePenak from "@privyid/vuelidate-penak";
import Vue from "vue";

Vue.use(VuelidatePenak);

In your form component

<template>
  <form @submit.prevent="handleSubmit">
    <vuelidate-penak :validator="$v.form.username" field="Username">
      <div slot-scope="{ errors, state }">
        <p class="form--label">
          Username
          <small class="red--text">*</small>
        </p>
        <v-text-field
          v-model="state.$model"
          dense
          outlined
          :error-messages="errors"
        ></v-text-field>
      </div>
    </vuelidate-penak>

    <vuelidate-penak :validator="$v.form.password" field="Password">
      <div slot-scope="{ errors, state }">
        <p class="form--label">
          Password
          <small class="red--text">*</small>
        </p>
        <v-text-field
          v-model="state.$model"
          type="password"
          dense
          outlined
          :error-messages="errors"
        ></v-text-field>
      </div>
    </vuelidate-penak>
  </form>
</template>

<script>
import { required, minLength } from "vuelidate/lib/validators"
export default {
    validations: {
        form: {
            username: { required },
            password: { required, minLength: minLength(8) }
        }
    }
    data() {
        return {
            form: {
                username: '',
                password: ''
            }
        }
    },
    methods: {
        handleSubmit() {
            this.$v.form.$touch()

            if(this.$v.form.$invalid) {
                return false
            }

            alert('Form Submitted')
        }
    }
}
</script>

Local Usage

<template>
  <vuelidate-penak :validator="$v.form.username" field="Username">
    <div slot-scope="{ errors, state }">
      <p class="form--label">
        Username
        <small class="red--text">*</small>
      </p>
      <v-text-field
        v-model="state.$model"
        dense
        outlined
        :error-messages="errors"
      ></v-text-field>
    </div>
  </vuelidate-penak>
</template>

<script>
import { VuelidatePenak } from "@privyid/vuelidate-penak";
import { required } from "vuelidate/lib/validators";

export default {
  components: {
    VuelidatePenak,
  },
  validations: {
    form: {
      username: { required },
    },
  },
  data() {
    return {
      form: {
        username: "",
      },
    };
  },
};
</script>

Custom Component

You can use component v-input from vuetify for show error messages

<template>
  <validator-form :validator="$v.form.balance_types" field="Custom Component">
    <div slot-scope="{ errors, state, invalid }">
      <p class="form--label">
        Balance Type
        <small class="red--text">*</small>
      </p>
      <your-custom-component
        v-model="state.$model"
        :class="{error--input: invalid}"
      ></your-custom-component>
      <v-input :error-messages="errors"></v-input>
    </div>
  </validator-form>
</template>

or if your custom component not use v-model to change the value

<template>
  <validator-form :validator="$v.form.balance_types" field="Custom Component">
    <div slot-scope="{ errors, state, invalid }">
      <p class="form--label">
        Balance Type
        <small class="red--text">*</small>
      </p>
      <your-custom-component
        :value="state.$model"
        :class="{error--input: invalid}"
        @change="state.$model = $event"
      >
      </your-custom-component>
      <v-input :error-messages="errors"></v-input>
    </div>
  </validator-form>
</template>

Custom Message

Global Setting

import VuelidatePenak from "@privyid/vuelidate-penak";
import Vue from "vue";

Vue.use(VuelidatePenak, {
  messages: {
    required: "{{field}} tidak boleh kosong",
  },
});

Spesific Input Form

<template>
    <vuelidate-penak
        :validator="$v.form.username"
        field="Username"
        :messages="{
            required: "{{field}} tidak boleh kosong"
        }"
    >
        <div slot-scope="{ errors, state }">
            <p class="form--label">
                Username
                <small class="red--text">*</small>
            </p>
            <v-text-field
                v-model="state.$model"
                dense
                outlined
                :error-messages="errors"
            ></v-text-field>
        </div>
    </vuelidate-penak>
</template>

You can also pass the params from vuelidate $params See here.
Or you can create your custom $params See here

<template>
    <vuelidate-penak
        :validator="$v.form.no_hp"
        field="No. Hp"
        :messages="{
            minLength: "{{field}} tidak boleh kurang dari {{min}}"
        }"
    >
        <div slot-scope="{ errors, state }">
            <p class="form--label">
                Username
                <small class="red--text">*</small>
            </p>
            <v-text-field
                v-model="state.$model"
                dense
                outlined
                :error-messages="errors"
            ></v-text-field>
        </div>
    </vuelidate-penak>
</template>

<script>
import { minLength } from "vuelidate/lib/validators"
export default {
    validations: {
        form: {
            no_hp: { minLength: minLength(8) }
        }
    }
    data() {
        return {
            form: {
                username: '',
                password: '',
            }
        }
    },
    methods: {
        handleSubmit() {
            this.$v.form.$touch()

            if(this.$v.form.$invalid) {
                return false
            }

            alert('Form Submitted')
        }
    }
}
</script>

Custom Validations

Vuelidate Penak not handle custom validation, because this package just help you to show the error message. So if you want to custom validation you just setting the custom validation at vuelidate. You can see here to more example for custom validation vuelidate Documentation Vuelidate

<template>
  <form @submit.prevent="handleSubmit">
    <vuelidate-penak
      :validator="$v.form.username"
      field="Username"
      :messages="{ mustContainBudi: '{{field}} harus mengandung kata budi' }"
    >
      <div slot-scope="{ errors, state }">
        <p class="form--label">
          Username
          <small class="red--text">*</small>
        </p>
        <v-text-field
          v-model="state.$model"
          dense
          outlined
          :error-messages="errors"
        ></v-text-field>
      </div>
    </vuelidate-penak>

    <vuelidate-penak :validator="$v.form.password" field="Password">
      <div slot-scope="{ errors, state }">
        <p class="form--label">
          Password
          <small class="red--text">*</small>
        </p>
        <v-text-field
          v-model="state.$model"
          type="password"
          dense
          outlined
          :error-messages="errors"
        ></v-text-field>
      </div>
    </vuelidate-penak>
  </form>
</template>

<script>
import { required, minLength } from "vuelidate/lib/validators"
export default {
    validations: {
        form: {
            username: { required, mustContainBudi: (value) => String(value).toLowerCase().includes('budi') },
            password: { required, minLength: minLength(8) }
        }
    }
    data() {
        return {
            form: {
                username: '',
                password: ''
            }
        }
    },
    methods: {
        handleSubmit() {
            this.$v.form.$touch()

            if(this.$v.form.$invalid) {
                return false
            }

            alert('Form Submitted')
        }
    }
}
</script>

or you can setting the message in global

import VuelidatePenak from "@privyid/vuelidate-penak";
import Vue from "vue";

Vue.use(VuelidatePenak, {
  messages: {
    mustContainBudi: "{{field}} harus mengandung kata budi",
  },
});

Props

| Props Name | Type | Default | Description | | :---------- | :------- | :------------- | :-------------------------------------------------------------------- | | validator | object | - | Required. The validator from vuelidate | | field | string | This Field | The field name for your error message | | messages | object | empty object | Custom Error Message |

Slots

| Slot Name | Slot Scope | Description | | :-------- | :------------------------------------------- | :--------------------------------- | | default | object<ValidationsType> | Required. The default Vue slot |

Validations Type

{
  state: object,
  invalid: boolean,
  errors: string[]
}

Important Notes

The state in slot scope is base on validator from vuelidate so technically this is props. So if you strict with rule props cannot change directly, you can use state form or $v.form instead.

instead use this

<template>
    <vuelidate-penak
        :validator="$v.form.no_hp"
        field="No. Hp"
    >
        <div slot-scope="{ errors, state }">
            <p class="form--label">
                Username
                <small class="red--text">*</small>
            </p>
            <v-text-field
                v-model="state.$model"
                dense
                outlined
                :error-messages="errors"
            ></v-text-field>
        </div>
    </vuelidate-penak>
</template>

You can use this

<template>
  <vuelidate-penak
      :validator="$v.form.no_hp"
      field="No. Hp"
  >
      <div slot-scope="{ errors, state }">
          <p class="form--label">
              Username
              <small class="red--text">*</small>
          </p>
          <v-text-field
              v-model="$v.form.no_hp"
              dense
              outlined
              :error-messages="errors"
          ></v-text-field>
      </div>
  </vuelidate-penak>

  // or this

  <vuelidate-penak
      :validator="$v.form.no_hp"
      field="No. Hp"
  >
      <div slot-scope="{ errors, state }">
          <p class="form--label">
              Username
              <small class="red--text">*</small>
          </p>
          <v-text-field
              v-model="form.no_hp"
              dense
              outlined
              :error-messages="errors"
          ></v-text-field>
      </div>
  </vuelidate-penak>
</template>

TODO

  • Create example codesandbox
  • Create component for Vue 3 & Vuelidate Next
  • Update Docs for Vue 3 & Vuelidate Next