asp.net mvc - MVC.net JQuery Validation -
after trying avoid javascript years, iv started using jquery validation in mvc asp.net, there not seem official way of doing validation, iv been surprised how jquery is.
firstly there way intellisense working jquery , validation plugin, don have learn api?
secondly how create validation summary this, appends error right of text box.:
<script type="text/javascript"> $().ready(function() { $("#createlog").validate({ rules: { username: { required: true, minlength: 2, } }, messages: { username: { required: "please enter username", minlength: "your username must consist of @ least 2 characters", } } }); }); </script> <form id="createlog" action="create" method="post" /> <label>username</label><br /> <%=html.textbox("username")%> <br /> <div class="error"> </div> <input type=submit value=save /> </form>
i tried adding script:
errorlabelcontainer: $("#createlog div.error")
and html:
<div class="error"> </div>
but didn't work.
try specifying both wrapper , label container in options. added display:none; style of error-container let jquery decide when show it.
html:
<div class="error-container"> <ul> </ul> </div> <form id="createlog" action="create" method="post" /> <label>username</label><br /> <%=html.textbox("username")%> <br /> <input type=submit value=save /> </form>
script:
<script type="text/javascript"> $().ready(function() { $("#createlog").validate({ errorlabelcontainer: $("ul", $('div.error-container')), wrapper: 'li', rules: { username: { required: true, minlength: 2, } }, messages: { username: { required: "please enter username", minlength: "your username must consist of @ least 2 characters", } } }); }); </script>
that should work.
Comments
Post a Comment