我有一個多形式,在一開始需要用戶的基本信息與某些jquery.validate錯誤檢查,看看是否領域已填寫和電子郵件地址是有效的。JQuery驗證表單輸入,如果某些複選框被檢查
下面有新帳戶的一系列複選框(type_of_request),刪除帳戶,新的軟件等,這顯示/隱藏的表單元素,因爲他們選中/取消。
我想驗證只有在corressponding type_of_request項目已經檢查了表格上所需要的部分。
更新信息
這是一個很好的解決方案,但似乎使所有需要,選擇部分的孩子。
一個典型的場景將是雙方在type_request電子郵件和其他複選框被選中:
<div id="email" style="display: block;"> // shown because other has been selected in the type request
<input id="email_new_account" class="sq-form-field" type="checkbox" value="0" name="q4836:q1"/> // not required
<input id="email_new_account_name" class="sq-form-field" type="text" name="q4836:q2"/> // if email_new_account checked then make required
<input id="email_new_account_access" class="sq-form-field" type="text" name="q4836:q2"/> // if email_new_account checked then make required
<input id="email_new_account_manager" class="sq-form-field" type="text" name="q4836:q3"/> // if email_new_account checked then make required
<input id="email_add_remove_access" class="sq-form-field" type="checkbox" value="0" name="q4837:q1"/> // not required
<input id="email_add_remove_account_name" class="sq-form-field" type="text" name="q4837:q2"/> // if email_add_remove_access checked then make required
<input id="email_add_access" class="sq-form-field" type="text" name="q4836:q2"/> // if email_add_remove_access checked then make required
<input id="email_remove_access" class="sq-form-field" type="text" name="q4837:q3"/> // if email_add_remove_access checked then make required
</div>
<div id="other" style="display: block;"> // shown because other has been selected in the type request
<input id="other_describe_request" class="sq-form-field" type="text" name="q4838:q1"/> // required because #other was checked in type request
<input id="other_request_justification" class="sq-form-field" type="text" name="q48387:q2"/> // required because #other was checked in type request
</div>
進一步閱讀
我已對進一步發現,以下內容可添加到輸入項目的類別中
class="{required:true, messages:{required:'Please enter
your email address'}}"
或
class="{required:true, email:true, messages:{required:'Please enter
your email address', email:'Please enter a valid email address'}}"
,但是當我添加
class="{required:'input[@name=other]:checked'}"
這是在
http://jquery.bassistance.de網站描述
,這是行不通的。我是否需要更改語法以使其正常工作?
不知道爲什麼語法突出顯示似乎不適用於所有這些。 – tvanfosson 2008-11-18 01:44:40