unobtrusive-validation

How to manually revalidate / trigger validation using unobtrusive jQuery validation?

房东的猫 提交于 2019-12-01 15:48:22
I have created my own conditional validation attribute to validate my MVC model on both the client and the server by inheriting from RequiredAttribute and implementing IClientValidatable . The idea is that if a boolean property on my model is true, then another property is required. In the view this manifests itself as a checkbox which dictates whether a textbox needs to be filled in. This works perfect except for when the user performs the following actions: Checks the checkbox (the field is now required). Submits the form (client side validation runs, error message displayed). User unchecks

How to manually revalidate / trigger validation using unobtrusive jQuery validation?

余生长醉 提交于 2019-12-01 15:30:05
问题 I have created my own conditional validation attribute to validate my MVC model on both the client and the server by inheriting from RequiredAttribute and implementing IClientValidatable . The idea is that if a boolean property on my model is true, then another property is required. In the view this manifests itself as a checkbox which dictates whether a textbox needs to be filled in. This works perfect except for when the user performs the following actions: Checks the checkbox (the field is

unobtrusive jQuery validation on elements created by javascript MVC3

时光毁灭记忆、已成空白 提交于 2019-12-01 08:03:26
I have a register form created by mvc3 scaffolding. e.g. <div class="editor-label"> @Html.LabelFor(model => model.Email) </div> <div class="editor-field"> @Html.EditorFor(model => model.Email) @Html.ValidationMessageFor(model => model.Email) </div> and so on. I have a dropdownlist where the user can select if hes a person or a company. If person is selected the page loads with the person's properties, like birthdate, but if he/she selects the option 'company', I switch out a part of the form (with jquery .detach() .attach()) to a hidden div outside the form (so the values aren't posted on

unobtrusive jQuery validation on elements created by javascript MVC3

瘦欲@ 提交于 2019-12-01 06:30:49
问题 I have a register form created by mvc3 scaffolding. e.g. <div class="editor-label"> @Html.LabelFor(model => model.Email) </div> <div class="editor-field"> @Html.EditorFor(model => model.Email) @Html.ValidationMessageFor(model => model.Email) </div> and so on. I have a dropdownlist where the user can select if hes a person or a company. If person is selected the page loads with the person's properties, like birthdate, but if he/she selects the option 'company', I switch out a part of the form

Custom RegularExpressionAttribute missing data-val-regex-pattern for client-side validation

陌路散爱 提交于 2019-12-01 06:05:40
I have created the following custom RegularExpressionAttribute [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)] public class AlphaNumericAttribute: RegularExpressionAttribute, IClientValidatable { public AlphaNumericAttribute() : base("^[-A-Za-z0-9]+$") { } public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context) { yield return new ModelClientValidationRule { ErrorMessage = FormatErrorMessage(metadata.GetDisplayName()), ValidationType = "alphanumeric" }; } } The field in the ViewModel is

Custom RegularExpressionAttribute missing data-val-regex-pattern for client-side validation

吃可爱长大的小学妹 提交于 2019-12-01 04:18:06
问题 I have created the following custom RegularExpressionAttribute [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)] public class AlphaNumericAttribute: RegularExpressionAttribute, IClientValidatable { public AlphaNumericAttribute() : base("^[-A-Za-z0-9]+$") { } public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context) { yield return new ModelClientValidationRule { ErrorMessage =

show div if unobtrusive validation was invalid and hide it if Valid in MVC 3

时光总嘲笑我的痴心妄想 提交于 2019-11-30 22:13:59
This is a part of my Edit view: <dt> @Html.LabelFor(model => model.MainModel.StartDate) </dt> <dd> @Html.TextBoxFor(model => model.MainModel.StartDate) @Html.ValidationMessageFor(model => model.MainModel.StartDate) <div class="targetDiv"> My content </div> </dd> So as all of you know when StartDate field in my model not valid unobtrusive show the error message and if valid hide it. Now I want to add another action to this process. I need if StartDate value is Invalid show "targetDiv" div and if StartDate value is Valid hide it. what is your suggestion? You can check for field validity with

Unobtrusive Validation on en-GB Dates

天大地大妈咪最大 提交于 2019-11-30 21:16:08
I am designing a data input form using asp.net MVC4 which has an input of type date. Using the unobtrusive jQuery library in chrome and jQueryUI datepicker I was still getting an error (The field news_date must be a date.), after selecting a correct date format, using the datepicker (i.e. 14/02/2013) and submitting the form. Some searching suggested I should use the jQuery.globilization library. So after reading the documentation I added a reference to the following script. $(document).ready(function () { $.culture = Globalize.culture("en-GB"); $.validator.methods.date = function (value,

jQuery.Validation.Unobtrusive client side validation only works when scripts are on view page

无人久伴 提交于 2019-11-30 20:05:57
I have an ASP.NET MVC 4 App that uses the jQuery.validation.js plugin and MVC's jQuery.validation.unobtrusive.js . I use data annotations on my view model to validate a textbox's input to be an integer. This (nested) view is loaded within a parent view using... <% Html.RenderPartial("New"); %> One the first inital page load, client side validation works. But any reloading of the nested view with an ajax call, client side validation no longer works. Why is that? Update : (Code example from webdeveloper's solution below) $.validator.unobtrusive.parse($('form')); Example: var saveAndUpdate =

jquery.validate v. 1.9 ignores some hidden inputs

☆樱花仙子☆ 提交于 2019-11-30 19:59:23
问题 with version 1.7 everything works ok, all hidden inputs get validated, but with version 1.9 some do and some don't I use asp.net mvc 3 and jquery.validate + jquery.unobtrusive (jquery 1.7.1) this is the generated html: <!--this gets validated--> <input type="hidden" data-val="true" data-val-number="The field Chef must be a number." data-val-required="The Chef field is required." value="" name="Chef" id="Chef"> <span data-valmsg-replace="true" data-valmsg-for="Chef" class="field-validation