Problem
There is an array of input text fields. JQuery validate only first textbox. Below is my code. Am I missing anything?
Html is below
<form class="panel-body" id="UpdateProfile">
<div class="row">
<div class="col-md-10">
<div class="form-group">
<input type="text" value="" name="VideoUrl[]">
</div>
</div>
</div>
<div class="row">
<div class="col-md-10">
<div class="form-group">
<input type="text" value="" name="VideoUrl[]">
</div>
</div>
</div>
<input type="submit">
</form>
JQuery
<script>
$(document).ready(function() {
$("form#UpdateProfile").validate({
ignore: [],
rules: {
'VideoUrl[]': "required"
},
messages: {
'VideoUrl[]': "Please enter Video Url"
},
submitHandler: function(form) {
var VideoUrls = [];
$.each($('input[name="VideoUrl[]"]'), function(index, row){
var data = {
"VideoUrl": row.value
};
VideoUrls.push(data);
});
var data = {
"VideoUrls": VideoUrls
};
console.log(data);
}
});
});
</script>
rulesobject, each field must be specified by its uniquename. You cannot use anyname, even an array name, if it appears on more than one field. Otherwise only the first occurrence is validated. The only exception is radio and checkbox groups.nameon each field. It's a mandated requirement of this plugin.