alex / alex/django-ajax-validation

Delayed validation would be nice, here's how I do it now

Abierto
#12 1 comentario 1 reacción 0 asignados Ver en GitHub
Lenguaje dominante
Python
Estrellas
251
Forks
57
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

It would be nice if you could tell the validation function that it should wait 500 ms after the last onkey event before it starts validating. That way you have almost instant feedback on what you're typing, but you're not sending a request to the server for _every_ character.

Here's how I'm doing it now:


<script type="text/javascript">
$(document).ready(function() {

var timers = [];
var selectorAndFields = [['#id_username',['username']],
['#id_email',['username','email']],
['#id_password1',['username','email','password1']],
['#id_password2',['username','email','password2', 'password1']]];

for (i = 0; i < selectorAndFields.length; i++) {
// bind the validation function to the change event for the input field.
$('#signUpForm').validate('{% url registration_form_validation %}', {type: 'table', fields: selectorAndFields[i][1], dom: $(selectorAndFields[i][0]), event: 'change'});

// trigger a change event 500 msecs after the last keyup-event for the same input field.
$(selectorAndFields[i][0]).keyup(function() {
var field = $(this);
if (timers[i]) { clearTimeout(timers[i]); }
timers[i] = setTimeout(function(){field.trigger('change')},500);
});
}

});
</script>

I've set it up so that it validates the field in which the user is typing but also all the fields above. (I thought it would be silly to get feedback on fields you haven't gotten to typing into yet).

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.