proengsoft/laravel-jsvalidation ReferenceError: jQuery is not defined

1.7k views Asked by At

I'm using proengsoft/laravel-jsvalidation to validate my custom form requests but it does not work with me, it gives ReferenceError: jQuery is not defined . Searched a lot about the problem even in its documentation but could not find it. Any help is appreciated.

//app view
@include('partials.nav')
@include('errors.errors')
@yield('content')

<!-- Scripts -->
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.1/js/bootstrap.min.js"></script>

<!-- Laravel Javascript Validation -->
<script type="text/javascript" src="{{ asset('vendor/jsvalidation/js/jsvalidation.js')}}"></script> 

My form to be validated

//Upload Form
{!! Form::model($paper, ['method' => 'POST', 'id' =>'uploadPaper',  'action' => ['PaperController@papershow', $paper->id], 'files' => true]) !!}    

       @include('partials._paperForm',['submitBtn' => 'Show Paper Details'])

   {!! Form::close() !!}

   <!-- Laravel Javascript Validation -->
   {!! JsValidator::formRequest('App\Http\Requests\PaperRequest'); !!}

My custom request:

//App\Http\Requests\PaperRequest
public function rules()
{
    return [ 'title'=> 'required|min:10',
                'type' => 'required',
                'keywords'=> 'required|min:10',
                'abstract'=> 'required|min:50',
                'dept_name' => 'required|min:3',
                'file'  =>  'required|mimes:pdf|max:10000',];}
1

There are 1 answers

0
haakym On BEST ANSWER

Make sure you are loading jQuery before you load the validation.js which depends on it.

From docs:

This package also depends of jQuery, but it's not bundled into provided script, you have to include manually

To use this package you muts include jQuery and before the provided public/vendor/jsvalidation/js/jsvalidation.js script

https://github.com/proengsoft/laravel-jsvalidation/wiki/Dependencies