2011-07-20 22 views
14

नोट: नीचे कोड सिर्फ प्रदर्शन के लिए है और मैं jQuery और jQuery मान्य प्लगइन का उपयोग कर रहा हूँ।क्षेत्रों मैन्युअल रद्द करने के लिए मान्य

मान लीजिए मैं दो क्षेत्रों (ईमेल और सूची संख्या) के साथ एक रूप है:

<form action="/something" method="post" id="demoForm"> 
    Inventory No: <input type="text" class="required" name="inventory_no" /> 
    Email: <input type="text" class="required" name="email" /> 
    <input type='submit' value='submit' /> 
</form> 

फार्म के लिए बाध्यकारी प्लगइन:

jQuery(function(){ 
    jQuery('#demoForm').validate(); 
}); 

//handle user submit 

jQuery('#demoForm').bind('submit', function (e) { 
    e.preventDefault(); 

    if (jQuery(e.target).valid()) { 
     //form is valid submit request thru ajax 

     jQuery.ajax({ 
      /*more options here*/ 

      success: function (data) { 

       /* 
       Server process request and finds that, email is already in use 
       and inventory number is invalid 
       so it sends data in some format may pe JSon 
       with field names and message indicating errors 
       eg: Email:"Already in use" 
       InventoryNo: "Invalid Inventory No", 
       Now can i invalidate these two fields on form mannualy 
       and display the message received from server for each field 
       */ 
      } 
     }); 
    } 
}); 
+0

आप कभी भी इस के लिए एक समाधान मिला? यह वास्तव में क्या मैं इस समय क्या करना कोशिश कर रहा हूँ है। – Richard

+0

मैं इसमें कुछ समय बस मुझे देने के लिए एक समाधान मिल गया है, मैं, यू पता –

उत्तर

31

क्या आप जानते हैं जो फ़ील्ड अमान्य है, तो आप इस का उपयोग कर सकते समारोह। http://docs.jquery.com/Plugins/Validation/Validator/showErrors

var validator = $("#myshowErrors").validate(); 
validator.showErrors({ 
    "firstname": "I know that your firstname is Pete, Pete!" 
}); 

कहाँ firstname अपने क्षेत्र के नाम संपत्ति है, यानी name="firstname"

+0

सही जवाब दूँगी आप श्रीमान धन्यवाद! (ओपी इस एक को स्वीकार करना चाहिए।) –

+16

यह एक त्रुटि दिखाई देगा लेकिन फार्म अभी भी प्रस्तुत करेगा – Lyon

संबंधित मुद्दे