
Security News
PodRocket Podcast: Inside the Recent npm Supply Chain Attacks
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
vue-material-vuelidate
Advanced tools
Vuelidate is a model-based validation for Vue.js that decouples validations nicely from the template.
This package (components MdVuelidated
and MdVuelidatedMsg
) simplifies
using Vuelidate together with Vue Material:
MdField
, MdAutocomplete
, MdChips
and MdDatepicker
As a module:
$ npm install vue-material-vuelidate
or
$ yarn add vue-material-vuelidate
Included as <script>
:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/vue-material-vuelidate/dist/components.css">
<script src="https://cdn.jsdelivr.net/npm/vue-material-vuelidate/dist/components.min.js"></script>
import MdVuelidated from 'vue-material-vuelidated'
import 'vue-material-vuelidated/dist/components.css'
...
// This must come after Vue.use(VueMaterial) and Vue.use(Vuelidate):
Vue.use(MdVuelidated)
In order to validate
<md-field>
(any type of <input>
),
<md-autocomplete>
,
<md-chips>
or
<md-datepicker>
:
<md-vuelidated>
.field
.validations
object of your component in the usual way.model
to the respective validations
member, e.g. $v.input
.v-model
for the input depends on the input component, see the examples
below.All examples assume that a suitable validations
object has been defined.
Validating text:
<md-vuelidated field="md-field" :model="$v.email">
<label>Enter your email address</label>
<md-input type="email" v-model.trim="$v.email.$model" />
</md-vuelidated>
Validating a selection:
<md-vuelidated field="md-field" :model="$v.toppings">
<label>Select at most two toppings</label>
<md-select v-model.trim="toppings" multiple>
<md-option value="1">Pepperoni</md-option>
<md-option value="2">Mushrooms</md-option>
<md-option value="3">Onions</md-option>
</md-select>
</md-vuelidated>
Validating an autocomplete field:
<md-vuelidated field="md-autocomplete" :md-options="colors" :model="$v.color">
<label>Select a color</label>
</md-vuelidated>
Validating a chips field:
<md-vuelidated field="md-chips" md-placeholder="Enter keywords" :model="$v.keywords">
</md-vuelidated>
Validating a date:
<md-vuelidated field="md-datepicker" :model="$v.birthday">
<label>Select your birthday</label>
</md-vuelidated>
Validation messages can be specified in two ways (both methods can be combined):
As the messages
property of <md-vuelidated>
.
This property must be bound to an object containing the message for each Vuelidate
constraint, e.g. :messages="{ required: 'This field is required' }"
.
These messages appear below the corresponding input field.
As <md-vuelidated-msg>
elements, either inside <md-vuelidated>
or somewhere else.
The Vuelidate constraint must be bound to property constraint
, see the examples below.
Messages placed inside <md-vuelidated>
appear below the corresponding input field.
Messages outside <md-vuelidated>
are visible only if their container has CSS-class md-invalid
.
Using the messages
property:
<md-vuelidated
field="md-field"
:model="$v.email"
:messages="{
required: 'Your mail address is required',
email: 'Not a valid mail address',
}">
<label>Enter your email address</label>
<md-input type="email" v-model.trim="$v.email.$model" />
</md-vuelidated>
As <md-vuelidated-msg>
tags:
<md-vuelidated field="md-field" :model="$v.email">
<label>Enter your email address</label>
<md-input type="email" v-model.trim="$v.email.$model" />
<md-vuelidated-msg :constraint="$v.email.required">Your mail address is required</md-vuelidated-msg>
<md-vuelidated-msg :constraint="$v.email.email">Not a valid mail address</md-vuelidated-msg>
</md-vuelidated>
Combining both methods:
<md-vuelidated
field="md-field"
:model="$v.email"
:messages="{ required: 'Your mail address is required' }">
<label>Enter your email address</label>
<md-input type="email" v-model.trim="$v.email.$model" />
<md-vuelidated-msg :constraint="$v.email.email">Not a valid mail address</md-vuelidated-msg>
</md-vuelidated>
Software: MIT
Documentation: CC-BY-SA 4.0
FAQs
A Vue Material adapter for Vuelidate
We found that vue-material-vuelidate demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.