Here i want to make all dynamic fields required that are calling from an ajax page so in order to make all fields required i wrote the code like this
<script src="http://demo.expertphp.in/js/jquery.validate.min.js"></script>
<script>
$('#toUploadButton').on('click', function(e){
e.preventDefault();
e.stopPropagation();
$('input.product_price').each(function() {
$(this).rules("add",
{
required:true,
messages: {
required: "Name is required",
}
});
});
e.preventDefault();
$("#add_product").validate();
});
</script>
My ajax view file looks like this
<tr class="tr_clone_product ajax_result">
<td style="width:200px;"><input class="product_price" type="text" name="product_price[]" id="product_price" style="width:200px;"></td>
</tr>
My main view file is here
<form method="POST" name="add_product" id="add_product" enctype="multipart/form-data" action="{{ url('/admin/products/store') }}">
@csrf
<div class="col-12">
<table class="table table-bordered all_products">
<thead>
<tr>
<th>SKU</th>
<th>Name</th>
<th>Qty</th>
<th>Price</th>
<th></th>
</tr>
</thead>
<tbody class="product_list">
</tbody>
</table>
</div>
</div>
<div class="form-group row">
<div class="offset-4 col-8">
<button name="toUploadButton" type="button" id="toUploadButton" class="btn btn-primary">Submit</button>
</div>
</div>
Here in the place of class product_list
the ajax page is loading and i want to make all the fields inside the ajax page to be required but the problem is only the first row is becoming required