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

lv-form-validator

v1.0.16

Published

Laravel Form Validator with File Upload For Vue.js included Axios

Downloads

6

Readme

Laravel form validation with Vue.js

Repository used to handle Laravel form validation with Vue.js. Plus point is File Upload Included. Special thanks to MetinSeylan Laravel validation component. Much inspired from there.

Install with NPM

npm i lv-form-validator --save--dev 

Dependencies

  • Vue
  • Axios

This package is using Axios to make ajax request. Also, behind the scene Vue.use() plugin is working. FormData class of JavaScript is helped to create form object with file upload.

Example

You can pass normal input element by v-model binding. But v-model not supports file_input type.

Here I used custom JavaScript selector to handle file Input type. ID or Class selector of input can be used here.

May example can help: Vue code:

import  LVFormValidator  from  'lv-form-validator';
Vue.use(LVFormValidator);

export default {
    name: 'app',
	data () {
		return {
			form: this.$form({
				title: 'foo',
				// fileOne: '.fileUploadOne', // Element By class Selector
				// fileOne: '#fileUploadOne', // Element By id Selector
			})
		}
  	},
	methods: {
		sendForm(){
			this.form.post('http://example.sr/myajax').then((response) => {
				
			}, (response) => {
				
			});
		}
	}
}

Here is the template file:

<template>
	<div>
		<form @submit.prevent="sendForm" autocomplete="off">
			<div class="row">
			
				<div class="col-sm-6">
					<div class="form-group">
						<label for="title">Title: </label>
						<input type="text" name="title" class="form-control" v-model="form.$fields.title" id="title" autocorrect="off" />
						<div  v-if="form.$errors.has('title')" id="titleHelp" class="text-danger"> 
							<small v-for="error in form.$errors.get('title')">
								<div>{{error}}</div> 
							</small> 
						</div><!-- /#titleHelp -->
					</div><!-- /.form-group -->
					
					<div class="form-group">
						<label for="picture">File Upload: </label>
						<input type="file" id="picture" class="picture" />
						<div v-if="form.$errors.has('picture')" id="pictureHelp" class="text-danger">
							<div>{{form.$errors.first('fileOne')}}</div> 
						</div><!-- /#firstHelp -->
					</div><!-- /.form-group -->
					
					<input type="submit" value="Submit" class="btn btn-sm"/>
				</div><!-- /.col-sm-6 -->
			</div><!-- /.row -->
		</form><!-- /form -->
	</div>
</template>

Laravel Validations example:

public function store(Request $request){
    $this->validate($request, [
        'name' => 'required|min:3|max:32',
        'picture' => 'required|image',
    ]);
}

Available Properties

All properies are same as here. Here is one new property to get first message only.

| Title | Type | Description | | ------------------------- | ------- | ---------------------------------------------------------------------- | | .$busy | Boolean | Flag will true when request sent and will false when request completed | | .$errors.get({input}) | Array | To get specific fields all errors | | .$errors.first({input}) | string | To get specific fields first error | | .$errors.has({input}) | Boolean | To check error key is exist | | .$errors.all() | Array | To get all errors | | .$fields.{input} | Input | To get raw input value (use in template) | | .post(url) | string | To send Laravel POST Request | | .put(url) | string | To send Laravel PUT Request | | .delete(url) | string | To send Laravel DELETE Request | | .get(url) | string | To send Laravel GET Request | | .patch(url) | string | To send Laravel PATCH Request |

Notes

  • Component with create FormData Object and then do request. Means it will use multipart/form-data with every ajax request.
  • With every request Component will default send _method parameter to indentify Laravel Routing Request.

That's it. Plugin include Laravel 5.5 and Laravel 5.6 support.