2011-09-10 5 views
1

jquery 유효성 검사 플러그인을 사용하여 동적으로로드 된 양식의 유효성을 검사합니다. 어떤 경우에는 $ .post를 사용하여 내용을로드하고 콜백에서 유효성 검사 규칙을 추가하는 함수를 호출합니다. 그거야. 일부 콘텐츠의 경우 $ .get을 사용하고 콜백에서 유효성 검사 규칙을 추가하는 함수를 호출하고 있습니다. 그러나 $ .get을 사용하면 양식이 전혀 검증되지 않습니다..post에서 jquery 유효성 검사를 연결했지만 .get에 없습니다.

내 문제는 무엇입니까? 게시물을 사용하여 실제로 어떤 종류의 차이점이 있습니까?

나는 이것이 중요한 코드라고 생각하지만, 필요한 경우에 대비해 많은 코드를 추가했다.

$.get("http://localhost/SMICAdmin/adminactivities/admin_update_agent.php", { agent_id: $agentid }, function(data){ 
        //Now, add the validation rules: 
        addUpdateAgentValidation(); 

        $('#dialog-modal').dialog("option", "title", 'Uppdatera agent'); 
        $("#dialog-modal").html(data).dialog("open"); 

이 양식로드 코드입니다 :

function addUpdateAgentValidation(){ 
     //alert("GETDONE 2"); 
        $("#updateagentform").validate({ 
          errorContainer: "#updateagentmessagebox", 
          errorLabelContainer: "#updateagentmessagebox ul", 
          wrapper: "li", debug:true, 


          rules: { 


           email1: {// compound rule 
           // required: true, 
           email: true 


           }, 
           email2: { 
            // required: true, 
            equalTo: "#email1" 
           }, 
           username: { 
           // required: true, 
            remote: "http://localhost/SMICAdmin/smicsoap/soap_is_agentusername_available.php" 

           }, 
           password: { 
           // required: true         
           }, 

           password2: { 
            //required: true, 
            equalTo: "#password1" 
           } 
          }, 
          messages: { 

           email1: {// compound rule 
           email: "Korrekt emailadress saknas" 

           }, 
           email2: { 
            equalTo: "Mailadresserna matchar inte varandra" 
           }, 
           //username: "Anv‰ndarnamnet mÂste vara unikt" 
           username: { 
            remote: "Användarnamn finns redan" 
           }, 


           password2: { 
            equalTo: "Lösenord inte lika" 
           } 
          } 
          }); 
        }; 
: 여기

$("#agents td").live('click',function(event) 
     { 
      //alert("Agents"); 
      event.preventDefault(); 

      var col = $(this).parent().children().index($(this)); 

      var $td= $(this).closest('tr').children('td'); 
      var $agentid=$td.eq(2).text(); 
      var $name=$td.eq(3).text(); 

      if(col==0){ 

       $.get("http://localhost/SMICAdmin/adminactivities/admin_update_agent.php", { agent_id: $agentid }, function(data){ 
        //alert("GETDONE"); 
       //Now, add the validation rules: 
       addUpdateAgentValidation(); 

       $('#dialog-modal').dialog("option", "title", 'Uppdatera agent'); 
       $("#dialog-modal").html(data).dialog("open"); 


       }); 
       //and the rest of the code 
       //. 
       //. 

를 검증 규칙을 추가하는 기능은이 내가 유효성 검사 규칙을 추가하는 함수를 호출하는 곳이다

여기는 양식을 게시하는 곳입니다.

$("#updateagentform").live("submit", function(e){ 
       //Prevent the form from submitting normally 

      // alert("Trying to submit user update"); 

      e.preventDefault(); 

      $.post("http://localhost/SMICAdmin/adminactivities/admin_update_agent.php",$(this).serialize(),function(msg){ 
       //alert the response from the server 
       //alert(msg); 
       $("#dialog-modal").dialog("close"); 

      }); 
      $("#usertable").empty(); 
      $('#usertable').load("http://localhost/SMICAdmin/adminactivities/admin_load_agents.php"); 
      $("#modalarea").empty(); 
      $('#modalarea').css("visibility","hidden"); 
     }); 

및 형태 생성 코드 :

echo "<div class='errormessage' id='updateagentmessagebox'> 
       <ul></ul> 
      </div> 
      <form id='updateagentform' method='post'> 
       Ändra önskade fält<br/> 
       * Förnamn: <input type='text' name='firstname' /> <br/> 
       * Efternamn: <input type='text' name='surname' /> <br/> 
       * Email: <input id='email1' type='text' name='email1' /> <br/> 
       * Repetera email: <input id='email2' type='text' name='email2' /> <br/> 

       * Användarnamn: <input id='username_ID' type='text' name='username' /><br/> 
       * Lösenord: <input id='password1' type='text' name='password' /><br/> 
       * Repetera lösenord: <input id='password2' type='text' name='password2' /><br/>"; 
     foreach ($roles as $key=>$role) { 
      if(in_array($key, $role_ids)){ 
       echo "<input type='checkbox' name='rid".$key."' value='rid".$key."' checked />".$role."<br/>"; 
      }else{ 
       echo "<input type='checkbox' name='rid".$key."' value='rid".$key."' />".$role."<br/>"; 
      } 

     } 

     echo "<input id='submitupdateagentform' type='submit' value='Uppdatera agent' /></form>"; 

어떻게 내 문제는 내가 그것을 어떻게 해결합니까를?

답변

1

아직 페이지에없는 양식에 .validate()을 호출하고 있습니다. 일

$.get("http://localhost/SMICAdmin/adminactivities/admin_update_agent.php", { agent_id: $agentid }, 
    function(data){ 
     $('#dialog-modal').dialog("option", "title", 'Uppdatera agent'); 

     $("#dialog-modal").html(data).dialog("open"); 
     addUpdateAgentValidation(); 
    }); 
+0

감사 :

$.get("http://localhost/SMICAdmin/adminactivities/admin_update_agent.php", { agent_id: $agentid }, function(data){ // form does not exist in DOM here addUpdateAgentValidation(); $('#dialog-modal').dialog("option", "title", 'Uppdatera agent'); // form exists after this line. $("#dialog-modal").html(data).dialog("open"); }); 

당신은 .validate()이 형태가 DOM에 추가됩니다 후 을 호출되는 그래서 함수 호출을 재 배열 할 필요가있다. 사실, 당신이 도둑질하는 것과 같은 이유 때문에, 어떻게 작동하지 않겠습니까? $ ("# dialog-modal") .html (data, function() { addUpdateCustomerUserValidation(); }}) .dialog ("open"); – Nicsoft

+1

@Nicsoft : 그것은'.html()'의 함수 인수의 버전이 함수에서 새로운 HTML을 반환하기를 기대하기 때문입니다. HTML이 추가 된 후에 실행되는 콜백 함수가 아닙니다. –

+0

그래, 나는 함수가 실행 된 후 정상적인 콜백이라고 생각했다. 나는 함수를 호출하기 전에로드되었는지 확인하기 위해 거기에 두었습니다. 이제 나는 더 잘 압니다. 감사! – Nicsoft

관련 문제