formValidation error with remote validator

1

My main problem was that I was trying to get a true / false from the controller to check the existence of an item in the database, (you can see it here) . The error was resolved, then I saw that one of the users, of the questions that they suggested, I work with jqueryvalidate (here's the question) , then it occurred to me to do it with the plugin that I'm using, between aa the plugin options (here you can see) you can see that they handle external validations in the same way. Then use your documentation and try to do it myself and I have problems, which are as follows:

Again, the one from the previous question:

  

javascript? v = 1480049567: 1145 Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check link .

this other error:

  

POST link 500 (Internal Server Error)

he checked his result with Fiddler

  

InvalidArgumentException in Builder.php line 1203: Illegal operator and value combination.

and this other error:

  

formValidation.min.js: 4 Uncaught TypeError: b.success is not a function (...)   f @ formValidation.min.js: 4   validate @ formValidation.min.js: 4   validateField @ formValidation.min.js: 1   (anonymous function) @ formValidation.min.js: 1   (anonymous function) @ formValidation.min.js: 1   dispatch @ jquery.min.js: 3   q.handle @ jquery.min.js: 3

Here at this website I got a forum where they talk about how to do what I want to do.

I present to you what I have done:

Ajax code formValidation:

            $('#form-crear').formValidation({
            framework: 'bootstrap',
            icon: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                CrearNombre: {
                    validators: {
                        notEmpty: {
                            message: 'El campo Nombre es requerido'
                        },
                        stringLength: {
                            min: 5,
                            max: 30,
                            message: 'El Nombre de 5 a 30 caracteres de largo'
                        },
                        regexp: {
                            regexp: /^[a-zA-Z]+$/,
                            message: 'El Nombre solo puede contener letras'
                        },
                        remote: {
                            message: 'El Cargo no esta disponible',
                            url: 'cargos/comprobacion',
                            type: 'POST'
                        }
                    }
                }
            }
        });

Here the controller:

    public function comprobacion(Request $req) {
        try{
            $isAvailable = true;
            if (Cargos::where('nombre', 'ilike', $req->get('CrearNombre'))->exists()) {
                $isAvailable = false;
            } else {
                $isAvailable = true;
            }
            return \Response::json(array('valid' => $isAvailable));
        }catch(\Illuminate\Database\QueryException $e){
            $array = array(
                'mensaje' => $e->getMessage(),
                'codigo' => $e->getCode(),
                'sql' => $e->getSql(),
                'bindings' => $e->getBindings(),
            );
            return Response::json(array('ErrorSql' => $array));
        }
}

What other information do you need?

    
asked by Pablo Contreras 26.11.2016 в 07:16
source

1 answer

2
  • For the message:

      

    javascript? v = 1480049567: 1145 Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check link .

    Surely there is a call ajax which has async: false set. If so, simply remove this configuration.

  • For messages:

      
    • POST link 500 (Internal Server Error)
    •   
    • InvalidArgumentException in Builder.php line 1203: Illegal operator and value combination.
    •   
    • The variable sent is not $req->valor , it is $req->CrearNombre . Modify your query like this:

      $sql = Cargos::select('id')->where('nombre', '=', $req->CrearNombre)->get();
      

      Keep in mind that $req->CrearNombre can not be null .

  • For the message:

      

    formValidation.min.js: 4 Uncaught TypeError: b.success is not a function (...) f @ formValidation.min.js: 4 validate @ formValidation.min.js: 4 validateField @ formValidation.min.js: 1 (anonymous function) @ formValidation.min.js: 1 (anonymous function) @ formValidation.min.js: 1 dispatch @ jquery.min.js: 3 q.handle @ jquery.min.js: 3

    Do not use jQuery v3.x . FormValidation requires jQuery v1.9.1 or higher, but less than v3

answered by 27.11.2016 / 04:53
source