I have a form I am using in a partial view (a password change form). I have written out a nice set of jquery validation rules, sitting in a script on the main page (not the partial). This is completely ignored.
I now understand that I have to use jQuery unobtrusive validation as well. Is this correct?
I am unwilling to use Umbraco Forms because (a) I can't afford it
b) I don't see why I should need it.
I enclose my code
Model
public class ChangePasswordModel
{
[Required]
[DisplayName("New Password")]
public string NewPassword { get; set; }
[Required]
[DisplayName("Confirm Password")]
public string VerifyPassword { get; set; }
}
View
<script>
/* The passwords must match */
//$(".validation-summary-errors").removeClass("validation-summary-errors");
//$(".input-validation-error").removeClass("input-validation-error").parent().addClass("has-error");
$().ready(function() {
// validate the changePasswordForm
$("changePasswordForm").validate({
rules: {
newPassword : {
required:true,
minlength: 5
},
verifyPassword:{
required:true,
minlength: 5,
equalTo: "#newPassword"
}
},
messages: {
newPassword: {
required: "Please provide a password",
minlength: "Your password must be at least 5 characters long"
},
verifyPassword: {
equired: "Please provide a password",
minlength: "Your password must be at least 5 characters long",
equalTo: "Please enter the same password as above"
}
}
});
});
public class ChangePasswordController: SurfaceController
{
public ActionResult ChangePassword(ChangePasswordModel model)
{
var memberService = Services.MemberService;
var membershipHelper = new MembershipHelper(UmbracoContext.Current);
var loggedInMember = membershipHelper.GetCurrentMember();
var member = memberService.GetById(loggedInMember.Id);
memberService.SavePassword(member,model.NewPassword);
return Redirect("/");
}
}
Got it. It's about relying on Data annotations and enabling client validation in the web.config. Then it all works really well. No need for any jquery validation scripting.
Form validation
Hi,
I have a form I am using in a partial view (a password change form). I have written out a nice set of jquery validation rules, sitting in a script on the main page (not the partial). This is completely ignored. I now understand that I have to use jQuery unobtrusive validation as well. Is this correct?
I am unwilling to use Umbraco Forms because (a) I can't afford it b) I don't see why I should need it.
I enclose my code
Model
public class ChangePasswordModel { [Required] [DisplayName("New Password")] public string NewPassword { get; set; } [Required] [DisplayName("Confirm Password")] public string VerifyPassword { get; set; } }
View@using ElyRunners.Models.CrudModels @inherits UmbracoTemplatePage @{ Layout = "Master.cshtml"; } @Html.Partial("~/Views/Partials/ChangePassword.cshtml", new ChangePasswordModel())
Partial View
@model ElyRunners.Models.CrudModels.ChangePasswordModel
Controller
Got it. It's about relying on Data annotations and enabling client validation in the web.config. Then it all works really well. No need for any jquery validation scripting.
is working on a reply...