Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

136
Vistas
Running Custom Validator in Parsley.js

I've defined a number of custom Parsley validators such as:

Parsley.addValidator('example', {
    validateString: function(value, id=0) {
        var max_length = 25
        var regex = /^[A-Z][a-z]+$/
        if (value.length > max_length) {
            return $.Deferred().reject(`Example <b>${value}</b> is longer than ${max_length} characters.`);
        }
        if (!regex.test(value)) {
            return $.Deferred().reject(`Example <b>${value}</b> must match regex <b>${regex}</b>.`);
        }
        return $.ajax({
            type: "GET",
            url: "/rest/api/example",
            data: {
                ratio: value
            },
            dataType: 'json'
        }).then(function(response) {
            if (!response) {
                return $.Deferred().reject("There was an error retrieving example.");
            }
            if (response.length > 0) {
                if ((id <= 0) || (response[0].id != id)) {
                    return $.Deferred().reject(`Example<b>${value}</b> is already in use.`);
                }
            }
        })
    }
});

This validation works as expected when using the HTML tag data-parsley-example on an input such as:

<input type="text" class="input" id="example" placeholder="Example" data-parsley-trigger="change" data-parsley-example="">

Is there a supported way to run this validation check in a standalone method? The following seems to work but uses the private _validatorRegistry:

Parsley._validatorRegistry["validators"].example.validate(value)

This is similar to How do I call a built-in parsley validator from javascript? but the recommended solutions don't appear to work for me.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

There is no API or it, but you can call it on virtual DOM, e.g.

$('<input data-parsley-example="">')
.parsley()
.whenValid({value})
.then(result => {...})
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda