1.0.16 • Published 6 years ago

lv-form-validator v1.0.16

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

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.

TitleTypeDescription
.$busyBooleanFlag will true when request sent and will false when request completed
.$errors.get({input})ArrayTo get specific fields all errors
.$errors.first({input})stringTo get specific fields first error
.$errors.has({input})BooleanTo check error key is exist
.$errors.all()ArrayTo get all errors
.$fields.{input}InputTo get raw input value (use in template)
.post(url)stringTo send Laravel POST Request
.put(url)stringTo send Laravel PUT Request
.delete(url)stringTo send Laravel DELETE Request
.get(url)stringTo send Laravel GET Request
.patch(url)stringTo 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.

1.0.16

6 years ago

1.0.15

6 years ago

1.0.14

6 years ago

1.0.13

6 years ago

1.0.12

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago