2012-05-19 3 views
1

음, 간단한 필드 유효성 검사 스크립트 등록을 개발했으며 일부 오류가있는 경우 일부 비어있는 경우 양식을 보내기 위해 버튼을 사용할 수 없도록 설정하려고했습니다.입력 오류를 카운트하고 제출 버튼을 사용 안 함 Jquery

하나 이상의 필드가 비어 있으면 보내기 버튼이 비활성화됩니다.

내 스크립트의 일부 :

$('#tipo_pessoa').focusout(function() { 
    if ($(this).val() == '') { 
     $(this).toggleClass('inputs_error-select') 
     $("label[for='tipo_pessoa']").fadeIn().html('<img src="../imagens/error.png" align="absmiddle" />&nbsp;Campo obrigatório'); 

     ErrorSound(); 
    } else { 
     $(this).toggleClass('inputs, inputs_error-select') 
     $("label[for='tipo_pessoa']").text(''); 

    } 
}); 


$('#razao_social').focusout(function() { 
    if ($(this).val() == '' || $(this).val() == $(this).attr("placeholder")) { 
     $(this).removeClass('inputs').addClass('inputs_error'); 
     $("label[for='razao_social']").fadeIn().html('<img src="../imagens/error.png" align="absmiddle" />&nbsp;O Campo Razão Social deve ser preenchido'); 
     ErrorSound(); 
    } else { 
     $(this).removeClass('inputs_error').addClass('inputs'); 
     $("label[for='razao_social']").text(''); 

    } 
}); 

내가 어떤 오류가 있는지 점검/카운트 스크립트를 필요는 하나 이상의 오류가있는 경우, 제출 버튼이 비활성화됩니다

+1

이 시도하고 얻을 많이하는 것입니다,하지만 당신은 단지 inputs_error-select' 클래스를'이 요소의 수를 계산 could'nt, 그 충분할 것이다. – adeneo

답변

1
당신은 양식 제출을 방지 할 수 있습니다

빈 필드가있는 경우 :

$('form').submit(function(e){ 
    return $('#input1, #input2').filter(function() { 
     return $.trim(this.value).length === 0; 
    }).length === 0; 
}); 
+0

누군가가 여기에 게시하는 것보다 더 많은 것을 가지고 있다면,이 기능을 테스트 할 것입니다. – Erivelton

관련 문제