unobtrusive-validation

jquery validate always returning true

人走茶凉 提交于 2019-12-18 13:29:47
问题 I am using MVC4 w/JQuery and I have a form I created using the @Ajax.BeginForm. It has required fields (set on its view model). I am trying to validate the form before it is submitted back; however, it does not seem to validate. I had a submit button originally and it was just submitting the form. I changed the submit button to a regular button and tried calling $('#formname').validate() but it always returns true (even tho required fields are not filled in). Other views seem to work fine

Forcing a revalidate on mvc3 unobtrusive remote validation

不问归期 提交于 2019-12-18 13:15:13
问题 It's a classic login flow. The user can choose between 'new user' or 'existing user'. If the user is new, the name in the login box should validate against the server to see if the username is unique, if it's an existing user this check will be skipped since we expect the username to be taken already (ofcourse). I added a [Remote] attribute on the viewmodel and added the radiobutton for new/exiting user as 'additional fields'. This way the remote validation will just return true if it's an

ASP.NET MVC validation message does not get localized

你说的曾经没有我的故事 提交于 2019-12-18 13:04:03
问题 I am using ASP.NET MVC 4 with unobtrusive clientside validation. The language in my application is german (defined in the web.config file) If i have a required field (configured with data-annotations in my Code First Classes), the client side validation works fine. the only downside: The Message is not Localized. The Field XXXX is required. Is there a solution out for this problem? 回答1: You must install the .NET Framework Language pack, according to your .NET Framework version: Microsoft .NET

How can I have a custom ValidationAttribute rendered as a 'data-val-xx' attribute on the client-side?

这一生的挚爱 提交于 2019-12-18 12:32:57
问题 Given a ViewModel that looks like this: public class Login { [Required] public string Username { get; set; } [Required, CustomValidator] public string Password { get; set; } } And a View like this (Razor syntax here): @Html.TextBoxFor(f => f.Password) I am getting the following markup: <input type="text" value="" data-val-required="This field is required." /> However I would like it to also include a 'data-' attribute for my custom validator. I want something like this: <input type="text"

Jquery validator reset $.validator.setDefaults({ onfocusout: false, onkeyup: false }); in MVC3

家住魔仙堡 提交于 2019-12-18 07:31:10
问题 are there any way to reset $.validator.setDefaults({ onfocusout: false, onkeyup: false }); in MVC3. I want to change the value in to some thing like $.validator.setDefaults({ onfocusout: true, onkeyup: true }); after I click a button. How to archive this? Thanks. 回答1: setDefaults should be set before $('form').validate() is called. Once validate() is called, the default are not used, so you must update the instance settings: var settings = $('form').validate().settings; settings.onkeyup = ...

Group validation messages for multiple properties together into one message asp.net mvc

蓝咒 提交于 2019-12-18 03:58:29
问题 I have a view model that has year/month/day properties for someone's date of birth. All of these fields are required. Right now, if someone doesn't enter anything for the date of birth they get 3 separate error messages. What I want to do is somehow group those error messages together into 1 message that just says 'Date of birth is required'. So if 1 or more of those fields are blank, they will always just get the 1 validation message. I NEED this to work on client-side validation via jquery

How to clear jquery validate errors

ε祈祈猫儿з 提交于 2019-12-17 22:54:34
问题 I'm hijaxing an existing form and POSTing to the server. jQuery validate does most of the validation but if validation fails on the server we return the errors to the client as JSON. Below is the code that does that: <script type="text/javascript"> $(function () { $("form").submit(function (e) { var $form = $(this); var validator = $form.data("validator"); if (!validator || !$form.valid()) return; e.preventDefault(); $.ajax({ url: "@Url.Action("index")", type: "POST", data: $form.serialize(),

.Net Mvc 3 Trigger (other than submit button) Unobtrusive Validation

别说谁变了你拦得住时间么 提交于 2019-12-17 18:25:58
问题 What I would Like I would like to trigger client-side validation in my View with an event of my choice. It could be 'onblur' maybe another button but something other than the submit button. Relevant Links How to trigger validation without using a submit button Applying unobtrusive jquery validation to dynamic content in ASP.Net MVC What I've tried Given a various event listener, I've fired the following methods with no luck: $(selector).validate(); $(selector).valid(); $.validator.unobtrusive

MVC3 unobtrusive validation not working in IE

此生再无相见时 提交于 2019-12-17 16:35:49
问题 I have MVC3 app, unobtrusive validation works fine in FireFox, but not working in IE. Any ideas why? UPDATE It seems that jQuery unobtrusive validation library that comes with MVC3 is not fully compatible with jQuery 1.7.1 that I am using (that came with bootstrap template). Works in Firefox, doesnt work with IE 8 (the one I have). I started to upgrade jQuery to the version where it begins to work (not sure though if other things don't break!). When I got to 1.8.1 it finally worked. I

ASP.NET MVC 3: Required steps for unobtrusive client-side validation of dynamic/AJAX content

眉间皱痕 提交于 2019-12-17 10:14:33
问题 What are the complete set of Steps Required for client-side unobtrusive validation to work for dynamically inserted form fields? Relevant SO posts ASP.NET MVC 3 unobtrusive client-side validation with dynamic content - He needed the unobtrusive validation attributes to show up in the generated HTML and did so by calling BeginForm ASP.Net MVC 3 validation on AjaxForm - The asker was using Ajax.BeginForm which uses MicrosoftAjax instead of JQuery.validation. PartialView and unobtrusive client