lundi 18 mai 2020

Use form valid() on button click for laravel-jsvalidation

jsvalidation validation with laravel and jquery.

This is my controller code.

protected $validationRules = [
        'title' => 'required',
        'body' => 'required',
];

public function edit($post_id)
{
    $validator = JsValidator::make($this->validationRules);
    $post = Post::find($post_id);

    return view('edit_post')->with([
        'validator' => $validator,
        'post' => $post,
    ]);
}

This is the blade.

<script type="text/javascript" src=""></script>
{!! $validator->selector('#my-form') !!}

My form validation works perfect. But I need something more. I need to see weather my form valid() inside anther button click.

This is my code.

$('.btn').click(function(){
   if($("#my-form").valid()){
   .....
   }
});

But when I click btn I get this error.

jquery.validate.min.js:4 Uncaught TypeError: Cannot read property 'call' of undefined. Exception occurred when checking element , check the 'laravelValidation' method. at a.validator.check (jquery.validate.min.js:4) at a.validator.checkForm (jquery.validate.min.js:4) at a.validator.form (jquery.validate.min.js:4) at n.fn.init.valid (jquery.validate.min.js:4) at HTMLButtonElement. (wizard?account=4:1489) at HTMLButtonElement.dispatch (jquery.min.js:3) at HTMLButtonElement.r.handle (jquery.min.js:3)



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire