I want it to validate when it leaves the field if the same data is not repeated in another input. Here my code and my progress
<input type="text" class="num_valido">
<input type="text" class="num_valido">
<input type="text" class="num_valido">
<input type="text" class="num_valido">
<input type="text" class="num_valido">
<input type="text" class="num_valido">
<input type="text" class="num_valido">
<input type="text" class="num_valido">
<input type="text" class="num_valido">
<input type="text" class="num_valido">
<script>
$(document).on('blur','.num_valido',function(){
var value = $(this).val(); //SACAMOS EL VALOR
var that = this;
if (!$.isNumeric(value)) //VALIDAMOS SI ES UN NUMERO
{
$(this).val($(this).data('')); //NO LO ES LO DEJAMOS EN BLANCO
}
else
{
if (value <= 0 || value > 10) //EL NUMERO DEBE ESTAR ENTRE 1 Y 10
{
$(this).val($(this).data('')); // SI NO LO DEJAMOS EN BLANCO
}
else
{
$('.num_valido').each(function(){
if($(this).val() == value)
{
$(this).val($(this).data('')); //LO DEJAMOS EN BLANCO SI YA ESTA EN OTRO input
return false; //CERRAMOS EL CICLO
}
});
}
}
});
</script>
The problem is that it is also validating the same field where it is detecting the blur, and obviously it is cleaning the field because if it exists in the path of the "num_valido". How do I do to validate all of them except the one I am triggering the blur?
EDIT ANSWER
$('.num_valido').each(function(){
if (that != this)
{
if ($(this).val() == value)
{
$(this).val($(this).data(''));
return false;
}
}
});
I differentiated that from this above I declared it. May it serve you. Thanks to yorodm who gave me the idea.