2
我試圖讓這個歐芹驗證一次只顯示一個確認郵件字段的錯誤消息。我嘗試了各種選項,並且priorityEnabled默認情況下也設置爲true。然而,仍然顯示兩條消息用於確認電子郵件消息。歐芹js驗證 - 確定約束和自定義錯誤消息的優先順序
<!Doctype html>
<html>
<head>
<style>
#fullnameErr {
display: inline-block;
}
</style>
<script src="jquery.js"></script>
<script src="parsley.js"></script>
</head>
<body>
<form id="demo-form" data-parsley-validate>
<!-- this field is just required, it would be validated on form submit -->
<label for="fullname">Full Name * :</label>
<input type="text" name="fullname" data-parsley-trigger="change" data-parsley-length="[1,6]" data-parsley-errors-container="#fullnameErr" required />
<div id="fullnameErr"></div>
<!-- this required field must be an email, and validation will be run on
field change -->
<label for="email">Email * :</label>
<input type="email" id="emailid" name="email" data-parsley-trigger="change" required />
<label for="email">Confirm Email * :</label>
<input type="email" name="email" data-parsley-trigger="change" data-parsley-equalto= "#emailid" required data-parsley-stop-on-first-failing-constraint="true" />
<!-- radio and checkbox inputs by default have to be wrapped in a parent
elemnt (here <p>) that will have success and error classes -->
<label for="gender">Gender *:</label>
<p>
M: <input type="radio" name="gender" id="genderM" value="M" required />
F: <input type="radio" name="gender" id="genderF" value="F" />
</p>
<!-- here, field is not required, it won't throw any error if no checkbox
is checked. But if checked, two at least must be checked -->
<label for="hobbies">Hobbies (2 minimum):</label>
<p>
Skiing <input type="checkbox" name="hobbies" value="ski" data-parsley-mincheck="2" />
Running <input type="checkbox" name="hobbies" value="run" />
Eating <input type="checkbox" name="hobbies" value="eat" />
Spleeping <input type="checkbox" name="hobbies" value="sleep" />
Reading <input type="checkbox" name="hobbies" value="read" />
Coding <input type="checkbox" name="hobbies" value="code" />
<p>
<!-- regular select input. Nothing more to add. -->
<label for="heard">Heard us by *:</label>
<select id="heard" required>
<option value="">Choose..</option>
<option value="press">Press</option>
<option value="net">Internet</option>
<option value="mouth">Word of mouth</option>
<option value="other">Other..</option>
</select>
<!-- this optional textarea have a length validator that would be checked on keyup after 10 first characters, with a custom message only for minlength validator -->
<label for="message">Message (20 chars min, 100 max) :</label>
<textarea name="message" data-parsley-trigger="keyup" data-parsley-length="[20, 100]" data-parsley-validation-threshold="10" data-parsley-minlength-message = "Come on! You need to enter at least a 20 caracters long comment.."></textarea>
<input type="submit" />
</form>
<body>
</html>