2013-10-02 5 views
0

.validity jquery 플러그인 (validity.thatscaptaintoyou.com/)을 사용하고 있습니다. 또한 .submit을 사용하려고하지만 두 가지를 방지하는 방법을 잘 모르겠습니다. 동시 실행 기본적으로 유효성이 확인되지 않으면 실행을 원하지 않습니다..valid와 함께 .submit을 사용하는 방법

유효 기간 확인 :

$("#myform").validity(function() { 
    $("#first_name").require(); 
    $("#last_name").require(); 
    $("#email").require().match('email', 'Please enter a valid e-mail address'); 
}); 

샘플 .submit

$('#myform').submit(function(event) {//Execute only if validity passed} 

답변

0

당신이 그들의 사용자 정의 모드 이것은 나를 위해 일한 (함수() {

// We'll decide to install our custom output mode under the name 'custom': 
$.validity.outputs.custom = { 


    end:function(results) { 


     if (results.valid) { 
      $('#myform').submit(function(event) {//Execute only if validity passed}); 
     } 

    } 
} 
})(); 

// Now enable the output mode we just installed. 
$.validity.setup({ outputMode:'custom' }); 
+0

나는 시도했지만, 유효성을 검증하지 않고 제출하거나 "end :"내에서 .submit을 실행한다. 또한 raise : 및 raiseAggregate : 옵션을 추가하려고 시도했지만 양식이 관계없이 제출되는 것과 동일한 결과가 발생했습니다. – dgraver

0

를 사용하여 시도 할 수 :

 function validateMyForm() { 

    // Start validation: 
    $.validity.start(); 

    // Validator methods go here: 
    $("#first_name").require(); 
    $("#last_name").require(); 
    $("#email").require().match('email', 'Please enter a valid e-mail address'); 

    // All of the validator methods have been called: 
    // End the validation session: 
    var result = $.validity.end(); 

    // Return whether it's okay to proceed: 
    return result.valid; 
} 

// Submit handler for /purchase 
$('#myform').submit(function(event) { 

//Execute only if validity passed 
     if (validateMyForm()) { 
       //Submit form or do whatever 

    }else{ 
       //Return False so form doesn't actually submit 
     return false; 
    } 
}); 
관련 문제