Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
vue-dotnet-validator
Advanced tools
A vuejs validator for .NET forms.
This package makes it possible to use .NET model validation using vue.js instead of the default jQuery validator way that microsoft dictates. The idea is that you use this on your server rendered HTML forms which include the data-attributes that are generated by C#'s razor template engine.
This package (from version 0.3.0 and up) requires vue 2.x.
npm install vue-dotnet-validator
Using this library requires changes on two places in your application, JavaScript and your razor cshtml templates.
This registers the vue components so that Vue.js knows what to activate. Base usage:
import { validatorGroup, validator } from 'vue-dotnet-validator';
Vue.component('validator-group', validatorGroup);
Vue.component('validator', validator());
The following code should be added to your cshtml forms. This makes sure that the validator logic is activated and adds the required references to DOM-nodes.
<validator-group inline-template>
<form asp-controller="Account" asp-action="Register" method="post" v-on:submit="validate">
<validator value="@Model.LastName" inline-template>
<span asp-validation-for="LastName" ref="message"></span>
<input type="text" asp-for="LastName" ref="field" v-model="val" />
</validator>
<button type="submit">Register</button>
</form>
</validator-group>
<validator-group inline-template>
This behaves as a container for the entire form, so we can maintain the state of the entire form and the validation status of the input fields in it.
v-on:submit="validate"
This adds an event listener to the <form>
tag to make sure we prevent the default form submit event when fields are invalid.
<validator value="@Model.LastName" inline-template>
This adds a validator instance to the form. The @Model.LastName
is the property of your model.
ref="message"
This adds a reference to the validation-message element. This makes sure the validation message is displayed at the correct position in the DOM.
ref="field"
This adds a reference to the input field, so the <validator>
instance knows what element to watch.
v-model="val"
This adds the model binding in the <validator>
instance.
validation-style=""
(optional, default is after-blur
), validation-styles:
after-blur
(default): After first blur validation will be reactive.after-change
: After first change validation will be reactive, blurring an autofocus field with no input will not trigger this.after-submit
: After first submit validation will be reactive.prioritize-extra-error-message
This prioritizes the (optional) extra error messages over the normal validation messages.
There are a couple of built-in validators you can use.
To validate if a value is not null
, undefined
or empty-string.
To validate a value (for example a checkbox) is set to true.
To validate a value is equal to the value of another input-field based on it's name attribute.
To validate a value complies to a regex.
To validate a numeric value is in a range between.
To validate a string value length is in a range between.
To validate a string value has a minimum length.
To validate a string is not longer than a maximum length.
It is possible to create your own validators, below is an example of a very simple custom validator.
import { validator, BaseValidator } from 'vue-dotnet-validator';
class MyCustomValidator extends BaseValidator {
isValid(value) {
return !value || value == 'Hello';
}
}
const validators = {
MyCustomValidator
};
Vue.component('validator', validator(validators));
To use this custom validator in your own form, make sure your custom .NET data annotation outputs a data-val-mycustom="MESSAGE"
attribute on your <input>
DOM node.
You can extend the features of your custom validators using additional data-attributes on your <input>
tag. This is a feature supported in .NET.
For an example on the usage of this feature, see regexvalidator.js
.
Make sure you have publish rights at the Q42 organisation on NPM.
npm version [major|minor|patch]
npm publish
FAQs
A vuejs validator for .NET forms.
The npm package vue-dotnet-validator receives a total of 215 weekly downloads. As such, vue-dotnet-validator popularity was classified as not popular.
We found that vue-dotnet-validator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 19 open source maintainers 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.