Search code examples
javascriptunobtrusive-validationunobtrusive-javascript

Unobtrusive javascript is not validating inactive Tabs


Yeah I know this question is asked but my question is different I have to validate I have tabs which are visible and invisible.. The tabs which are visible has obviously active and in active tabs I want to validate both active and inactive tabs which are visible I have tried this solution

$("#frmClaim").validate( 
 { ignore: [] }
);

but this things make validate all tabs which are visible and invisible Please help


Solution

  • I have Solved my Question by searching allot on this:

    ignore: ".ignore :hidden" is telling it to ignore hidden fields with the class ignore.

    ignore: ".ignore" will tell it to only ignore fields will class .ignore.

    ignore: ".ignore, :hidden" will tell it to ignore fields will class .ignore AND fields that are hidden.

    Without specifying the ignore option at all, the default is ignore: ":hidden" where it will only ignore hidden fields.

    Setting to ignore: [] tells the plugin to ignore nothing and validate everything.

    But The problem is if we used ignore :hidden it will not validate fields which are in Inactive tabs and if we use ignore :[] it will validate all fields which are in visible active,Inactive and Invisible active,inactive

    The only Solution i found is to Add class and Remove Class on your conditions Like

    First Add this code in document.ready

    $('#myform').validate().settings.ignore = ".ignore";
    

    Now just add ignore class on your tabs

    $('#tab_1_1 :input').addClass("ignore");
    

    And for remove

    $('#tab_1_1 :input').removeClass("ignore");