1

I have following jQuery validator in a MVC4 scenario. It is working fine. But I need the validation only when the user clicks the button; not when user change the textbox focus. How do we make this change?

jQuery

$(function ()
{

jQuery.validator.unobtrusive.adapters.add
    ("lijovalidator", ["param"], function (options)
    {
        options.rules["lijovalidator"] = options.params.param;
        options.messages["lijovalidator"] = options.message;
    });

jQuery.validator.addMethod("lijovalidator",
function (value, element, param) {

    alert(value);
    alert(param);
    alert(element);
    alert($("#" + param).val());

    return false;


});

}(jQuery));

Client Validation in SelctedValueCheckAttribute

public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
        {

            ModelClientValidationRule mcvr = new ModelClientValidationRule();
            mcvr.ValidationType = "enteredvaluescheck";
            mcvr.ErrorMessage = "Selected Value must be in given range";
            mcvr.ValidationParameters.Add("param", OtherProperty);
            mcvr.ValidationType = "lijovalidator";
            yield return mcvr;
        }

Model

   public class CrossFieldValidation
    {

        public IEnumerable<SelectListItem> Items { get; set; }

        [SelctedValueCheckAttribute("TxtCrossField") ]
        public string SelectedValue { get; set; }

        [Required]
        [Display(Name = "Quantity:")]
        public string TxtCrossField{ get; set; }

        public IEnumerable<SelectListItem> ShippingItems { get; set; }

        [SelctedValueCheckAttribute("ShippingValue")]
        public string SelectedShippingItemValue { get; set; }

        [Display(Name = "Quantity:")]
        [Required]
        public string ShippingValue { get; set; }



    }
Sparky
  • 98,165
  • 25
  • 199
  • 285
Glory Raj
  • 17,397
  • 27
  • 100
  • 203
  • 1
    Maybe [this](http://stackoverflow.com/questions/5252373/jquery-validate-rule-only-at-submit) will help. – Zabavsky Jul 31 '13 at 08:08

1 Answers1

0

Use as below:

$(function(){
   $(window).blur(function(){
      return true;
   });
});
Amit
  • 15,217
  • 8
  • 46
  • 68