2014-06-20 3 views
0

내 양식에 두 개의 제출 버튼이 있습니다. 하나는 기본 양식을 제출하고 다른 하나는 아약스를 사용하여 데이터를 전송합니다. 부트 스트랩 검사기에게이 경우 다른 제출 버튼을 사용하고 있다고 알려주는 방법을 알 수 없습니다. 그리고 네, 그것을 사용하여 메신저를 사용하여 preventDefault();부트 스트랩 검사기를 사용하여 대상 지정 제출 버튼

$("#submitformat").click(function(event) { 
    $('#formid').bootstrapValidator({ // this id is correct 
    message: 'This value is not valid', 
    fields: { 
     alias: { 
      message: 'The username is not valid', 
      validators: { 
       notEmpty: { 
        message: 'The username is required and cannot be empty' 
       }, 
       stringLength: { 
        min: 6, 
        max: 30, 
        message: 'The username must be more than 6 and less than 30 characters long' 
       }, 
       regexp: { 
        regexp: /^[a-zA-Z0-9_]+$/, 
        message: 'The username can only consist of alphabetical, number and underscore' 
       } 
      } 
     }, 
    } 
}); 

HTML 버튼 : Here

<button type="submit" id="submitformat" class="btn btn-primary">Submit</button> 

답변

0

Accordig 당신은 submitHandler 옵션 bootstrapvalidator 에 링크

에서 Taked 아약스

와 함께 사용하기 위해 사용해야 할

Ajax를 사용하여 양식 전송

Ajax를 사용하여 양식을 제출하고 그 후에 추가 작업을 수행하려는 경우 submitHandler 옵션을 사용할 수 있습니다.

주어진 사용자 이름과 암호를 사용하여 계정이 Ajax 요청 예라면을 통해 원격 URL로 보내이있는 경우

확인, 현재 페이지 를 다시로드 : 우리의 모달 예

시선

다음 코드는 방법을 보여줍니다 때 버튼 그렇지 않으면) (

<script> 
$(document).ready(function() { 
    $('#loginForm').bootstrapValidator({ 
     message: 'This value is not valid', 
     feedbackIcons: { 
      valid: 'glyphicon glyphicon-ok', 
      invalid: 'glyphicon glyphicon-remove', 
      validating: 'glyphicon glyphicon-refresh' 
     }, 
     submitHandler: function(validator, form, submitButton) { 
      $.post(form.attr('action'), form.serialize(), function(result) { 
       // The result is a JSON formatted by your back-end 
       // I assume the format is as following: 
       // { 
       //  valid: true,   // false if the account is not found 
       //  username: 'Username', // null if the account is not found 
       // } 
       if (result.valid == true || result.valid == 'true') { 
        // You can reload the current location 
        window.location.reload(); 

        // Or use Javascript to update your page, such as showing the account name 
        // $('#welcome').html('Hello ' + result.username); 
       } else { 
        // The account is not found 
        // Show the errors 
        $('#errors').html('The account is not found').removeClass('hide'); 

        // Enable the submit buttons 
        $('#loginForm').bootstrapValidator('disableSubmitButtons', false); 
       } 
      }, 'json'); 
     }, 
     fields: { 
      username: { 
       validators: { 
        notEmpty: { 
         message: 'The username is required' 
        } 
       } 
      }, 
      password: { 
       validators: { 
        notEmpty: { 
         message: 'The password is required' 
        } 
       } 
      } 
     } 
    }); 
}); 
</script> 

발견되지 않는 계정을 알리는 메시지를 표시 게다가이 .click을 덮어이 켜지지 아니다 있다 엄지 손가락 (버튼의 종류)

0

유효성 검사기는 아마도 양식 제출 방법에 상관하지 않을 것입니다. 어떤 버튼을 클릭했는지 감지하려면 다음과 같이해야 할 수 있습니다.

관련 문제