
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
laravel-form-validation
Advanced tools
This package make use of AJAX to validate your forms with backend logic.
npm install laravel-form-validation@^1.0
An example using Vue.js v2.7 and Bootstrap v4.6
<template>
<form @submit.prevent="submit">
<!-- Display a global message if there are any errors -->
<div class="alert alert-danger my-3" v-show="form.$errors.any()">
Please check the form and try again!
</div>
<div class="form-group">
<label>Name</label>
<input type="text"
class="form-control"
v-model="user.name"
:class="{ 'is-invalid': form.$errors.has('name') }"
@keyup="form.$errors.clear('name')">
<!-- Display first error for a field -->
<div class="invalid-feedback" v-show="form.$errors.has('name')">
{{ form.$errors.first('name') }}
</div>
</div>
<div class="form-group">
<label>Avatar</label>
<div class="custom-file">
<!-- Transform File object to FormData() automatically -->
<input type="file"
id="input-avatar"
accept="image/*"
:class="{ 'is-invalid': form.$errors.has('avatar') }"
@change="user.avatar = $event.target.files[0]">
<label class="custom-file-label" for="input-avatar">Choose image...</label>
<!-- Display all errors for a field -->
<div class="invalid-feedback" v-show="form.$errors.has('avatar')">
<div v-for="message in form.$errors.get('name')">{{ message }}</div>
</div>
</div>
</div>
<!-- Get file upload progress percentage using form.$progress -->
<div class="progress" v-show="form.$pending">
<div class="progress-bar" :style="{ width: form.$progress + '%' }">{{ form.$progress }}%</div>
</div>
<!-- Prevent re-submit using form.$pending -->
<button type="submit" :disabled="form.$pending">Submit</button>
</form>
</template>
<script>
import Form from 'laravel-form-validation';
export default {
data() {
return {
user: {name: 'Joy', avatar: null},
form: new Form()
}
},
methods: {
submit() {
this.form.post('/profile', this.user)
.then(response => {
// This is the data returned from your server
console.log(response);
})
.catch(error => {
// Handle errors
});
}
}
}
</script>
You can take a look at individual classes and their methods
This package comes with two helpers to work with bootstrap css
You can register the component and directive
import {VueFormPlugin} from "laravel-form-validation";
Vue.use(VueFormPlugin)
Setup global directive manually
import {IsInvalidDirective} from 'laravel-form-validation';
Vue.directive('invalid', IsInvalidDirective);
Use on form inputs, you must specify name
attribute on your input fields
<input type="email" v-invalid="form.$errors" name="email">
Setup global component manually
import {FieldErrorComponent} from 'laravel-form-validation';
Vue.component('field-error', FieldErrorComponent);
Use in forms to show validation message for specific field
<field-error :bag="form.$errors" field="email"></field-error>
axios
instance (optional)The package uses axios for making AJAX requests, you can pass your own axios instance and Form class will start using it.
// app.js
import axios from 'axios';
import Form from 'laravel-form-validation';
// Make your modifications
axios.defaults.headers.common['X-CSRF-TOKEN'] = window.Laravel.csrfToken;
axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
Form.$defaults.axios = axios;
This package is highly inspired by various other similar implementations:
__test__
folder.npm test
MIT License
FAQs
Yet another form validation helper for Laravel
The npm package laravel-form-validation receives a total of 14 weekly downloads. As such, laravel-form-validation popularity was classified as not popular.
We found that laravel-form-validation 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
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.