jquery-validate

Combining validation methods in jQuery Validation plugin with “or” instead of “and”

懵懂的女人 提交于 2019-12-12 17:05:12
问题 In the jQuery Validation plugin there are a couple of methods that do the same thing, but for different locales, for example dateISO and dateDE , that both validate date formatting. How do I combine these so that the input element accepts either ? Let's say I have an <input type="text" name="dateInput" id="dateInput" /> in my form, and I want to allow users to enter only dates in this field. However, I want to allow for several different date formats - for example, the user should be able to

Reset required fields - jQuery

六眼飞鱼酱① 提交于 2019-12-12 15:24:05
问题 I have some fields that I'm requiring depending on which button is clicked. The behavior I'm seeing though is not what I would expect nor desire. When I click one of the buttons, it sets the required fields as I'd like, but then if I click another button, it doesn't reset them for some reason. Code is below. Thanks for any help you can provide: function makeAllRequired() { $("#SomeForm").validate({ rules: { StartDate: { required: true, date: true }, Name: { required: true } }, errorElement:

JQuery Validate Plugin - Eager validation on custom method when should be lazy

早过忘川 提交于 2019-12-12 14:42:09
问题 The validate plugin seems to be eagerly validating on a custom method I have when it should be lazy, all other validation occurs lazily (i.e. not until the form is submitted). The custom method: $.validator.addMethod("refDataAcInput", function(value, element) { return ($(element).val() == "" || $(element).data("hasValidSelectedValue") != null); }, "The item must be a valid selected item."); Validate plugin init: this.$form.validate({ ignore: null, invalidHandler : function() { _self

Jquery validation does not validate numbers properly?

*爱你&永不变心* 提交于 2019-12-12 13:23:18
问题 I've got a problem with validation of numbers using jquery unobtrusive validation. The versions I'm using are: ASP.MVC 3. JQuery 1.9.1 JQuery UI 1.10.1 JQuery Validation 1.11.0 the input I'm trying to validate is : <input type="number" value="0" name="Data.time_between_loops.Planned.hour" id="Data_time_between_loops_Planned_hour" data-val-required="The hour field is required." data-val-range-min="0" data-val-range-max="23" data-val-range="The field hour must be between 0 and 23." data-val

jQuery validator: Call method added with addMethod

爷,独闯天下 提交于 2019-12-12 12:20:57
问题 How I can call a validate method created with jQuery.validator? Example: jQuery.validator.addMethod("functionA", function(value, element) { if($.trim(value)==""){ return false; } return true; }, "MSG A"); jQuery.validator.addMethod("functionB", function(value, element) { return jQuery.functionA(); //<--- How do I do it? }, "MSG B"); 回答1: Methods added with addMethod are inside the $.validator.methods object. You can call functionA like this: jQuery.validator.addMethod("functionB", function

Client validation of INPUT of type FILE without postback using jQuery

*爱你&永不变心* 提交于 2019-12-12 11:14:54
问题 I want to check on the client side that a file has been selected before the form can be submitted. <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script> <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script> @using (Html.BeginForm("Upload", "Files", FormMethod.Post, new { enctype = "multipart/form-data" })) { <input id="File" name="File" type="file" size="80" /> <input type="submit" name="name"

JQuery validate dynamically add rules

纵饮孤独 提交于 2019-12-12 10:37:09
问题 I am currently using the validate plugin to validate a form (using ASP.Net controls). I have stripped out the rules from the standard setup within the form.validate method ie: $("form").validate({ rules: { ctl00$ContentPlaceHolder1$dgQuestions$ctl14$iRadList_Col0: "required" } }); I now have these in various functions which add the ruless depending on what button is clicked. This works fine for text boxes, but for a RadiobuttonList when the plugin tries to add the rule there is an error

How do you validate optional fields with default value?

只谈情不闲聊 提交于 2019-12-12 10:19:28
问题 I made some changes to the following example: http://docs.jquery.com/Plugins/validation#Example <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <script src="http://code.jquery.com/jquery-latest.js"></script> <script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js"></script> <style type="text/css"> * { font-family: Verdana; font-size: 96%; } label { width: 10em; float: left; }

Client validation does not work on dom manipulated elements?

醉酒当歌 提交于 2019-12-12 10:19:09
问题 I have a simple form with a select element and an input element. Depending on the value in the select element i might or might not need the input element validated. What i did is, i set the 'data-val' attribute on the input element to either 'true' or 'false' depending on what is selected in the select element. This part is working - i can inspect the value of the attribute in firebug and it does change according to the plan. Now, in order to have the jquery unobtrusive validation to notice

Why do custom Unobtrusive Validator methods have to be added before document.ready runs?

寵の児 提交于 2019-12-12 10:14:46
问题 I'm working on an MVC4 app and needed some specific validation on a particular form. So I followed (several) tutorials on how to do this. Starting with a custom attribute: public class CheckDuplicateElementNameAttribute : ValidationAttribute, IClientValidatable { // Server side check omitted public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context) { ModelClientValidationRule rule = new ModelClientValidationRule(); rule