unobtrusive-validation

client side validation with dynamically added field

不羁的心 提交于 2019-11-27 18:49:48
I am using jQuery's unobtrusive validation plugin in with ASP.NET MVC. Any fields that are rendered on the server are properly validated. However, if I dynamically add a field in the form using JavaScript, it is not validated even though it has the appropriate HTML5 data-* attributes. Can anyone guide me in right direction on how I can achieve this goal? Sundara Prabu Simpler Answer: I am using MVC 4 and JQuery 1.8. I have made it to a modular function which accepts the jQuery object of the newly added element: function fnValidateDynamicContent($element) { var $currForm = $element.closest(

RequiredAttribute with AllowEmptyString=true in ASP.NET MVC 3 unobtrusive validation

霸气de小男生 提交于 2019-11-27 18:34:41
If i have [Required(AllowEmptyStrings = true)] declaration in my view model the validation is always triggered on empty inputs. I found the article which explains why it happens. Do you know if there is a fix available? If not, how do you handle it? Jon Galloway Note: I'm assuming you have AllowEmptyStrings = true because you're also using your view model outside of a web scenario; otherwise it doesn't seem like there's much of a point to having a Required attribute that allows empty strings in a web scenario. There are three steps to handle this: Create a custom attribute adapter which adds

MVC 4 client side validation not working

早过忘川 提交于 2019-11-27 18:27:44
Can anyone tell me why client side validation is not working in my MVC 4 application. _layout.schtml @Scripts.Render("~/bundles/jquery") @RenderSection("scripts", required: false) In my web.config I have: <appSettings> <add key="ClientValidationEnabled" value="true" /> <add key="UnobtrusiveJavaScriptEnabled" value="true" /> </appSettings> In my login.cshtml page I have: @using (Html.BeginForm()) { <div class="formscontent"> <ol> <li> @Html.LabelFor(x => x.AgreementNumber) <br /> @Html.TextBoxFor(x => x.AgreementNumber, new { size = "30" }) <br /> @Html.ValidationMessageFor(m => m

Error in jquery.validate.js in MVC 4 Project with jQuery 1.9

落花浮王杯 提交于 2019-11-27 18:05:20
I created a new ASP.Net MVC 4 project using the template in Visual Studio 2012. After upgrading to jQuery 1.9, the login functionality breaks. Specifically, I get the error 0x800a138f - JavaScript runtime error: Unable to get property 'call' of undefined or null reference at line 1172, column 5 in jquery.validate.js How can I fix this issue? Eric J. This issue is fixed in jQuery Validation Plugin 1.11.0pre . Unfortunately there is currently no pre-release build on NuGet, so it is currently necessary to download jquery.validation.js directly from GitHub: jQuery.Validation 1.11 is now available

MVC3 Unobtrusive Validation Not Working after Ajax Call

↘锁芯ラ 提交于 2019-11-27 17:05:14
Ok, here is the deal, I have seen a few posts on SO relating to this issue, but nothing is working for me. Basically, I have select drop downs that are being loaded from partial views, I am trying to filter contents of each subsequent drop down, based on the previously selected drop down. If I just put the call to the partial view in the div containers, and load the page, the validation from data annotations works fine, primarily Required attribute . However, if I try to load the same partial via AJAX as it is setup here, the Required validation does not work, anyone can post the form after

MVC unobtrusive validation on checkbox not working

北城以北 提交于 2019-11-27 17:03:46
I'm trying to implement the code as mentioned in this post . In other words I'm trying to implement unobtrusive validation on a terms and conditions checkbox. If the user hasn't selected the checkbox, then the input should be marked as invalid. This is the server side Validator code, I've added: /// <summary> /// Validation attribute that demands that a boolean value must be true. /// </summary> [AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = false)] public class MustBeTrueAttribute : ValidationAttribute { public override bool IsValid(object value) { return value

client-side validation trips on DataAnnotation Range attribute

风格不统一 提交于 2019-11-27 15:37:49
I have the following code in my Model class: [Range(1, 100)] public decimal Price { get; set; } After recent upgrade (I assume) of jquery.validate to 1.11.0, I am getting an error even if I enter valid value. If I turn off client validation in web.config - works fine. All other attributes (StringLength, Required) work fine. Generated HTML is the following (line breaks added for clarity): <input class="text-box single-line" data-val="true" data-val-number="The field Price must be a number." data-val-range="The field Price must be between 1 and 100." data-val-range-max="100" data-val-range-min=

ASP.Net MVC 3 unobtrusive client validation does not work with drop down lists

邮差的信 提交于 2019-11-27 15:11:47
问题 I have a simple drop down list, the first item in the list has an empty value. If I do not select anything in the list the client validation ignores it. I have that field set up as required on the model using annotation attributes. @Html.DropDownListFor(model => Model.CCPayment.State, UnitedStatesStates.StateSelectList) [Required(ErrorMessage = "State is Required.")] public string State { get { return _state; } set { _state = value; } } any ideas? am I missing something? 回答1: It looks like a

How to manually enable jQuery validation with ASP.NET MVC

丶灬走出姿态 提交于 2019-11-27 13:46:48
问题 I'm struggling to understand some of the basics of jQuery validation as wired up with ASP.NET MVC. The short version of this question is: What magic am I missing that allows the code produced by @Html.EditorFor() to perform jQuery validation, but doesn't work I try to wire up my own jQuery validation using the exact same HTML? As a learning exercise (and because it mimics what I really want to do in my website) I created a new MVC 4 app in Visual Studio 2012. I added a view model: using

Disable validation for an element with jQuery Unobtrusive Validation

天涯浪子 提交于 2019-11-27 13:22:30
问题 By some form generator a list of elements is rendered on a page and they all have validations on them. When I look in the HTML source, i see something like this: <input type="text" id="email" name="email" data-val-required="No valid email address!" data-val="true"> I need to somehow have a dynamic way to enable/disable the validation for such an element. I tried to enable/disable the data-val attribute, by setting it to false and then back to true . But it doesn't seem to be responding to