Skip to content

Commit 8745e50

Browse files
author
Jesse Leite
authored
Merge pull request #6 from RyanSMurphy/master
handle arrays and multi dimensional arrays
2 parents eb82e68 + 3115344 commit 8745e50

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/laravel-bootstrap-modal-form.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@ $('document').ready(function() {
8585
// Iterate through errors object.
8686
$.each(errors, function(field, message) {
8787
console.error(field+': '+message);
88+
//handle arrays
89+
if(field.indexOf('.') != -1) {
90+
field = field.replace('.', '[');
91+
//handle multi dimensional array
92+
for (i = 1; i <= (field.match(/./g) || []).length; i++) {
93+
field = field.replace('.', '][');
94+
}
95+
field = field + "]";
96+
}
8897
var formGroup = $('[name='+field+']', form).closest('.form-group');
8998
formGroup.addClass('has-error').append('<p class="help-block">'+message+'</p>');
9099
});

0 commit comments

Comments
 (0)