unobtrusive-validation

dynamically remove an element's required attribute in ASP MVC?

橙三吉。 提交于 2019-12-05 18:32:24
Is there a way, in an ASP MVC project using unobtrusive validation, to dynamically remove the Required attribute from an element? The element is decorated with a Required annotation in the view model. I thought I could remove this by removing the html attribute, "data-val-required," with JQuery but client validation still treats the element as required. Is it impossible to manipulate the element's validation by manipulating the unobtrusive validation attributes? This is what I tried, but it didn't work. I wanted to remove the required attribute if a check box was unchecked. $("#chkTempHire")

Globally Override ASP.Net MVC Default Attribute Error Messages

风格不统一 提交于 2019-12-05 16:20:50
How can I use resources from a different assembly to override the default attribute error messages in my MVC5 application? My website is namespaced: Company.Web My resources assembly is namespaced: Company.Web.Resources I can easily localize attribute error messages individually using: [Required(ErrorMessageResourceName = "PropertyValueRequired", ErrorMessageResourceType = typeof(Company.Web.Resources.Messages))] However, since our error message is always "Required", I'd simply like to put the [Required] attribute without having to specify the resource name. I'd also like to override the

MVC4 custom unobtrusive validator isn't working

守給你的承諾、 提交于 2019-12-05 12:16:17
not sure what is wrong. Syntax seems correct.... but it still doesn't fire on client side. If I submit the form, I get server side validation, client side nothing... Here is the code that is on the page: <script src="@Url.Content("~/Scripts/jquery.validate.min.js")"></script> <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")"></script> <script type="text/javascript"> // we add a custom jquery validation method (function ($) { $.validator.addMethod('additive', function (value, element, params) { //just return false to test it. return false; }); // and an unobtrusive

Event hooks for MVC unobtrusive remote validation

爷,独闯天下 提交于 2019-12-05 10:22:03
Is there a way to hook into MVC3 unobtrusive remote validation on the client, before data is submitted to the remote method, and after a result is returned from the remote method? I am trying to tell a remote validator to only perform validation if the submit button is clicked. The normal behavior is to validate several times, such as during keypress, blur etc. This is no good, as the validation method in question needs to call a non-idempotent operation. I need to make sure that method is only invoked if the user has clicked the submit button. If I could hook into a before event, I could set

server side validation in jquery dialog

孤人 提交于 2019-12-05 08:11:07
sorry for my language - in English i can only read :) i want to do in asp.net mvc something like this: 1. show user a page 2. open modal dialog (jquery-ui) and show partial view 3. validate user input data on client side 4. if it's OK then validate input data on server 5a. if it's OK then i want reload page 5b. if there is a errors i want show its to user 6. user can close dialog at any time with button on it. i have problem width 5a and 6. in Firefox when i do server validate and click close button (dialog('close')) when i get redirect to page that was call to validate data. if i click 'x' in

Trigger an event if there are validation errors?

你。 提交于 2019-12-05 05:38:14
I need to add an handle to any circumstance where a form validation fails. I've read this , that explains that I have to add a handler as follows: $('form').bind('invalid-form.validate', function () { console.log('form is invalid!'); }); But this event only fires when I try to submit the form. I need to handle an event that's fired ANY time the form is post-validated (i.e. element loses focus etc.). What I'm trying to achieve is, I have a large form (~50 fields), and it's splitted in Bootstrap tabs . I want, that when there is any new validation failure or success, set or clear an error class

Client-side validation of input type date does not work

大憨熊 提交于 2019-12-05 04:19:01
I have a form containing a date and datetime field: @Html.TextBoxFor(model => model.A, new { @type = "datetime" }) @Html.TextBoxFor(model => model.B, new { @type = "date" }) Model: public class TestModel { [DataType(DataType.Date)] public DateTime A {get;set;} [DataType(DataType.Date)] public DateTime B {get;set;} } By using these input types an iPad shows nice date(time) pickers. The fields are validated using client-side validation. For the datetime field ( A ) it works, but the date field ( B ) will raise an error: "please enter a valid date." How do I solve this? Examples: This iPad

How to make unobtrusive client-side validation work with Foolproof's ModelAwareValidationAttribute

天大地大妈咪最大 提交于 2019-12-05 02:39:21
问题 I'm trying to make use of the MVC Foolproof Validation framework (http://foolproof.codeplex.com/) but I'm having trouble with the ModelAwareValidationAttribute class. When I add a custom validation attribute, it works fine for server-side model validation, but not on the client-side. If I use one of the built-in attributes supplied by the framework, client-side unobtrusive validation works, so I know (or at least I think I know) that I have the correct javascript libraries loaded. Has anyone

How to in ASP.NET MVC prevent jquery ajax submit if validation fails

独自空忆成欢 提交于 2019-12-04 20:52:54
问题 I am using ASP.NET 5 MVC RC1 The jquery validation plugins that my ASP.NET MVC uses is the standard jquery.validate.js that a default ASP.NET 5 template project uses. /*! * jQuery Validation Plugin v1.14.0 * * http://jqueryvalidation.org/ * * Copyright (c) 2015 Jörn Zaefferer * Released under the MIT license */ and jquery.validation.unobtrusive.js /*! ** Unobtrusive validation support library for jQuery and jQuery Validate ** Copyright (C) Microsoft Corporation. All rights reserved. */ I

How to validate a list of checkbox through custom jQuery in asp.net mvc

馋奶兔 提交于 2019-12-04 19:37:00
I have a list of checkboxes that i want to validate on client side with jQuery but failing. I have already added unobtrusive and jquery validation plugin to my project. The Model code is: [Required] public string name { get; set; } [SkillValidation(ErrorMessage = "Select at least 3 skills")] public List<CheckBox> skills { get; set; } and other model is: public class CheckBox { //Value of checkbox public int Value { get; set; } //description of checkbox public string Text { get; set; } //whether the checkbox is selected or not public bool IsChecked { get; set; } } Explanation - SkillValidation(