Answer the question
In order to leave comments, you need to log in
How to use bootstrapValidator for forms that have been added to the home with append()?
There is an html table with input forms input[type=text]. In this table, it is possible to add rows with the same input forms using append().
<form action="/department/save" method="post" id="save_department">
<button type="button" class="btn btn-success" id="add-point"><i class="fa fa-plus"></i> Добавить</button>
<table class="table table-striped departments">
<tr>
<th>Название</th>
<th>Логин</th>
<th>Пароль</th>
</tr>
<tr class="item-department" >
<td class="form-group"><input type="text" class="form-control" name="department_name[]" ></td>
<td class="form-group"><input type="text" class="form-control" name="department_login[]" ></td>
<td class="form-group"><input type="text" class="form-control" name="department_password[]" ></td>
</tr>
</table>
<button type='submit' class="btn btn-success"><i class="fa fa-save"></i> Сохранить</button>
</form>
$(document).on('click', '#add-point', department.add);
function add() {
$('.departments').append('<tr class="item-department">' +
'<td class="form-group"><input type="text" class="form-control" name="department_name[]"></td>' +
'<td class="form-group"><input type="text" class="form-control" name="department_login[]"></td>' +
'<td class="form-group"><input type="text" class="form-control" name="department_password[]"></td>' +
'</tr>'
);
}
$('#save-department').submit(function() {
$(this).bootstrapValidator({
fields: {
'department_name[]': {
validators: {
notEmpty: {
message: 'Необходимо ввести название точки продаж'
}
}
},
'department_login[]': {
validators: {
notEmpty: {
message: 'Необходимо ввести логин точки продаж'
}
}
},
'department_password[]': {
validators: {
notEmpty: {
message: 'Необходимо ввести пароль точки продаж'
},
stringLength: {
min: 6,
max: 30,
message: 'Пароль должен быть не меньше 6 символов'
}
}
}
}
});
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question