Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I use Jquery Validate to validate a password but not require it?
    primarykey
    data
    text
    <p>I am wondering if anyone has used the Jquery Validate Password plugin ( <a href="http://bassistance.de/jquery-plugins/jquery-plugin-password-validation/" rel="nofollow">http://bassistance.de/jquery-plugins/jquery-plugin-password-validation/</a>) to validate passwords but not require them.</p> <p>In my case, I am putting together an edit user form. A user cannot exist without having a password. So when an admin is editing a user, I know that a password has already been validated and assigned to the user.</p> <p>I want the Admin to be able to submit the form and leave the password fields blank. This means that the password was not changed. But, if the admin does want to change the password, I want to use jquery validate password (linked above) to validate the password.</p> <p>In my html <code>&lt;head&gt;</code>, I have:</p> <pre><code>&lt;script src="/Scripts/Common/jquery.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="/Scripts/Common/jquery.validate.min.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="/Scripts/Common/jquery-validate.password/jquery.validate.password.js" type="text/javascript"&gt;&lt;/script&gt; &lt;link href="/Scripts/Common/jquery-validate.password/jquery.validate.password.css" rel="stylesheet" type="text/css" /&gt; &lt;script&gt; $(document).ready(function() { $("#edit").validate(); $("#password").valid(); }); &lt;/script&gt; </code></pre> <p>and in the <code>form</code> field (in Razor and MVC syntax):</p> <pre><code>@using (Html.BeginForm("Edit", "User", FormMethod.Post, new { id = "edit" })) { @Html.ValidationSummary() @Html.HiddenFor(model =&gt; model.UserAccount.UserAccountId) &lt;!-- other user fields removed for brevity --&gt; &lt;table&gt; &lt;tr&gt; &lt;th&gt;Password&lt;/th&gt; &lt;td&gt; @Html.PasswordFor(x =&gt; x.Password, new { id="password", @class="password"}) @Html.ValidationMessageFor(x =&gt; x.Password) &lt;/td&gt; &lt;td&gt; &lt;div class="password-meter"&gt; &lt;div class="password-meter-message"&gt; &lt;/div&gt; &lt;div class="password-meter-bg"&gt; &lt;div class="password-meter-bar"&gt;&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;p&gt; &lt;button type="submit"&gt;Save&lt;/button&gt; @Html.ActionLink("Nevermind", "Index") &lt;/p&gt; } </code></pre> <p>This works great. Though it requires a password to be entered. Can I modify it to not require the password and only validate it?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload