unobtrusive-validation

MVC3 Validation - Require One From Group

只愿长相守 提交于 2019-12-17 07:06:45
问题 Given the following viewmodel: public class SomeViewModel { public bool IsA { get; set; } public bool IsB { get; set; } public bool IsC { get; set; } //... other properties } I wish to create a custom attribute that validates at least one of the available properties are true. I envision being able to attach an attribute to a property and assign a group name like so: public class SomeViewModel { [RequireAtLeastOneOfGroup("Group1")] public bool IsA { get; set; } [RequireAtLeastOneOfGroup(

Unobtrusive validation not working on dynamically-added partial view

心已入冬 提交于 2019-12-17 05:40:53
问题 I am currently facing a problem with validation after dynamically adding content. I have a view strongly typed to a model ( Order ). This Order can have many items. The model looks something like the following: public class Order { [Key] [HiddenInput] public int id { get; set; } [Display(Name = "Order Number")] public string number { get; set; } [Display(Name = "Order Date")] [DataType(DataType.Date)] [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yyyy}")] public

attaching jquery validation to replacement element

喜夏-厌秋 提交于 2019-12-17 05:15:17
问题 I have an aspnet mvc form with a dropdown list in, that I am replacing with a jquery combobox. the original dropdownlist has a client validation set against it - using the unobtrusive lib along with the standard jquery validate - , and I would like this validation attached to the combobox instead. as part of the generation of the combobox, the name is removed from the dropper and instead set on a hidden field. the problem I am facing is that the validation message is then not showing for the

unobtrusive validation not working with dynamic content

☆樱花仙子☆ 提交于 2019-12-17 04:14:50
问题 I'm having problems trying to get the unobtrusive jquery validation to work with a partial view that is loaded dynamically through an AJAX call. I've been spending days trying to get this code to work with no luck. Here's the View: @model MvcApplication2.Models.test @using (Html.BeginForm()) { @Html.ValidationSummary(true); <div id="res"></div> <input id="submit" type="submit" value="submit" /> } The Partial View: @model MvcApplication2.Models.test @Html.TextAreaFor(m => m.MyProperty); @Html

Unobtrusive validation in Chrome won't validate with dd/mm/yyyy

蹲街弑〆低调 提交于 2019-12-17 03:56:42
问题 I'm trying to use the simplest possible scenario using a date picker in different browsers. I suspect I'm doing something very simple the wrong way but after lots of searching around I still haven't found a solution. Below is some sample code that represents what I'm attempting. If I use Chrome (v12.0.742.122) and pick a date from the picker like 13/08/2011 the jQuery validation logic will not allow the page to submit even though I've explicitly specified the format as 'dd/mm/yy'. If I change

Unobtrusive validation in Chrome won't validate with dd/mm/yyyy

戏子无情 提交于 2019-12-17 03:54:01
问题 I'm trying to use the simplest possible scenario using a date picker in different browsers. I suspect I'm doing something very simple the wrong way but after lots of searching around I still haven't found a solution. Below is some sample code that represents what I'm attempting. If I use Chrome (v12.0.742.122) and pick a date from the picker like 13/08/2011 the jQuery validation logic will not allow the page to submit even though I've explicitly specified the format as 'dd/mm/yy'. If I change

asp.net mvc TextAreaFor is not getting validated as a required field

这一生的挚爱 提交于 2019-12-14 03:45:50
问题 I have a data entry field where I'm gathering notes. The note data element is required for each note. Here's my model: public interface INoteDataEntryViewModel : IMobilePageDataContract { int CourseId { get; set; } [Required(ErrorMessage = @"Note is required")] String Note { get; set; } [DisplayName(@"Note Date")] DateTime NoteDate { get; set; } } You can see that I have the Required attribute for the Note property. I'm using Razor to display the data entry form element: <div data-role=

How to re-enable ASP.NET MVC unobtrusive validation on a field

有些话、适合烂在心里 提交于 2019-12-13 18:09:16
问题 I have a form with unobtrusive validation set up and all works well under most circumstances. However there are cases where I have to disable a select element in the form and then sometimes the element gets re-enabled (Mostly when QA is trying every possible circumstance but still). When this happens the "required" validation rule on the select element no longer works. I have tried removing and re-adding the required rule from the element's rules collection to no avail. I have tried wiring in

jquery validate not loaded requirejs

烂漫一生 提交于 2019-12-13 16:26:24
问题 I have a main module in RequireJS: require([ 'jquery', 'jquery.validate', 'jquery.validate.unobtrusive' ], function ($) { $(document).ready(function () { var validator = $("form").validate(); if ($("#txtFirstName").val() !== "") validator.element("#txtFirstName"); }); }); When I load this page, I get a JavaScript error: TypeError: $(...).validate is not a function var validator = $("form").validate();** I don't now why? All scripts are loaded: 回答1: You'll need to configure shim to "wire" the

Validate a field inside a validation function

☆樱花仙子☆ 提交于 2019-12-13 08:29:26
问题 This is related to this question: Validation for selecting a minimum and maximum So I have two fields one for minim and one for maxim that the user must enter. I need to have a validation on both field that they are correct minim < maxim. I have the following code $.validator.addMethod('lessthan', function (value, element, params) { var greatElement, validator, less, greatText, isEqualValid, great; greatElement = $(params[0]); // This code does not work //validator = $( greatElement[0].form )