2014-04-17 3 views
0

약 20-25 개의 필드가있는 양식이 있습니다. 나는 그들 중 어느 것도이어야 하나을 필요로하는 필드와 쇼 오류를 강조 표시 한 후 채워되지 않은 경우 검증양식의 한 입력 필드에만 입력 허용

  • 다음이 필요합니다 4 개 특정 필드가 모든 필드 중 요구 사항

    에게 다음 구현해야

  • 둘 이상이 채워지면 필드를 강조 표시하고 하나만 필요합니다.라는 오류를 표시하십시오.

JSON 파일에서 해당 필드의 선택자를 가져오고 있습니다. 여기에 내가이 코드는 내가 필요로하는 분야에 대한 선택 모든 필드

for(var i = 0; i < param.length; i++){ 
    selector = param[i].replace(/\s/g,"_") + "_Label"; 
    input ? input += ", input[aria-labelledby=" + selector + "]" : input = "input[aria-labelledby=" + selector + "]"; 

    $(input).each(function(e){ 
     //if($(this).val() != "") 
     SiebelJS.Log(this); 
    }); 

} 

를 선택하려면 다음 코드를 작성 할 수 있었다 필드 HTML이

<input type="text" name="s_18_1_2_0" value="" aria-labelledby="DC2_AP2-T_Transport_speed_-_Business_Label" aria-label="AP2-T Transport speed - Business" style="height: 30px; width: 140px;" maxlength="250" class="siebui-input-align-left ui-autocomplete-input siebui-input-popup undefined" autocomplete="off" role="combobox" tabindex="0" aria-readonly="false" aria-describedby=" s_18_1_2_0_icon"> 

<input type="text" name="s_18_1_8_0" value="" aria-labelledby="DC2_Pair_in_Operator_Label" aria-label="Pair in Operator trunk" style="height: 30px; width:150px;" maxlength="250" tabindex="0" class="siebui-input-align-left dc2-invalid" aria-readonly="false" title="Pair in Operator trunk is required field"> 

처럼 보이게하는 방법의 예입니다 유효성 검사를 수행하지만 주요 어려움은 부분 강조 표시이므로 유효성 검사에 실패한 필드의 선택자가 필요합니다. 필터 이외에도 필터를 사용할 수 있습니까?

도움이 될 것입니다.

+0

예, 필터를 사용하십시오. –

답변

0

첫째는 스타일 클래스를 선언

<style type="text/css"> 
    .error { 
     border:1px solid red; 
     background-color:yellow; 
    } 
</style> 

는 다음 코드를 시도 :

var maxLimit = 0; 
     var minLimit = 0; 
     $(input).each(function() { 
      if ($(this).val().length < 1) { 
       minLimit++; 
      } else { 
       maxLimit++; 
      } 
     }); 
     if (minLimit == $(input).length) { 
      $(input).addClass("error"); 
      alert("Message for required field"); 
     } 
     else if (maxLimit > 1) { 
      $(input).addClass("error"); 
      alert("Message to fill only 1 input value, not more"); 
     } 
     else if (minLimit != $(input).length && maxLimit < 2) { 
      $(input).removeClass("error"); 
     } 

이 당신을 도울 수 있습니다.