Validating multiple “array named” file inputs and dropdowns in JQuery Validate

前端 未结 1 501
陌清茗
陌清茗 2020-12-22 04:22

I have search lot of about this but haven\'t found any solution. I want to validate multiple array named file inputs and dropdowns in JQuery validate.



        
1条回答
  •  执念已碎
    2020-12-22 04:45

    The plugin doesn't handle fields with the same name well. Here's how I solved it in my application.

    I gave all the repetitive fields distinct names, and put the validation method names in the class.

      
    
    
      
    
    
      
    
    

    You can remove the indexes before submitting with code like this:

    $("#formname").validate({
        ...
        submitHandler: function(form) {
            $(form).find(":input[name*='[']").each(function() {
                this.name = this.name.replace(/\[\d+\]/, '[]');
            }
            form.submit();
        }
    });
    

    0 讨论(0)
提交回复
热议问题