0

I am using jquery validator plugin to validate inputs

liberary url : https://jqueryvalidation.org/

i have al form where input fieds are dynamically generated and each row input names are same

<tr>  <td><input type="text" class="form-control username" name="username"/></td> </tr>

when user click on add button then one more row will add

<tr>
 <td><input type="text" class="form-control username" name="username"/></td>
</tr>

i have following validation

$validator = $("#myform").validate(
             {
        rules: {
            username: {
                required: true,

            }


        }
    }
    );

my problem is this code will validate only first row username not dynamically generated field name

before asking question i have researched lots of thread no use.

i ref many links but not helped me much

jQuery Validate multiple fields with the same name

jquery get all input from specific form

jquery validate plugin on dynamic form inputs not working

jQuery Validation plugin doesn't validate dynamically created form elements

jQuery - How to dynamically add a validation rule

Vision Coderz
  • 8,257
  • 5
  • 41
  • 57
  • I think you need to add the fields like: `$newField.rules('add', { required: true });` when you click add button. Like this describes: https://stackoverflow.com/questions/20561712/jquery-validate-plugin-on-dynamic-form-inputs-not-working – AtheistP3ace Jun 29 '17 at 18:15
  • @AtheistP3ace.thanks you mean in on add new row i have to call this .also $newField means – Vision Coderz Jun 29 '17 at 18:16
  • Yes every time you add a new row you need specifically add the rule to the field. `$newField` is just a variable holding the input field you just added in the row. This one -> `` for each time you add it. – AtheistP3ace Jun 29 '17 at 18:17
  • To be honest 3 out of 5 of those links answer your question. Specifically the last 3. – AtheistP3ace Jun 29 '17 at 18:21
  • @AtheistP3ace.you are absultey right.my nad i have wasted 5 to 6 hours to fix this issue.but you saved finaly .thanks .one more is same issue forbootstrap modal form not triggering – Vision Coderz Jun 29 '17 at 18:23
  • If you create a new question for the modal issue I will try to help. – AtheistP3ace Jun 29 '17 at 18:27
  • sure.thanks for te response – Vision Coderz Jun 29 '17 at 18:30
  • @AtheistP3ace. as per your suggestion i tried its working for new element.suppose if i have already input value and if clear input and click on submit then it will submit.validation not working – Vision Coderz Jun 29 '17 at 18:44

0 Answers0