/home/mip/mip/app/Modules/Client/Views/principals/includes/modal-requiredjs.blade.php
<script type="text/javascript">
$(function() {
$('#principal-modal').on('hide.bs.modal', function () {
var form = $('form#principal-modal-form');
var formGroup = $('form#principal-modal-form .form-group');
var formGroupErrorDiv = $('form#principal-modal-form .form-group div.error');
formGroup.removeClass('has-error');
formGroup.removeClass('has-success');
formGroupErrorDiv.html("");
$('#principal-modal-message-wrapper').html("");
form[0].reset();
});
$('#principal-save-btn').click(function(){
var form = $(this).closest('form');
var action = form.attr('action');
var btn = $(this);
var formGroup = form.find('.form-group');
var formGroupErrorDiv = form.find('.form-group').find('div.error');
$.ajax({
type: "POST",
url: action,
dataType: 'json',
data: form.serialize(),
success: function(data) {
if(data.type == "success") {
formGroup.removeClass('has-error');
formGroup.removeClass('has-success');
formGroupErrorDiv.html("");
$('<option value="'+data.row.id+'">'+data.row.name+'</option>').appendTo('#vessel-modal #principal_id');
$('#vessel-modal #principal_id').select2('val', data.row.id);
$("#vessel-modal #principal_id").select2('close');
form[0].reset();
show_alert(data.message, 'success', 'principal-modal-message-wrapper');
}else{
show_alert(data.message, 'error', 'principal-modal-message-wrapper');
}
},
error :function( jqXhr ) {
//
if( jqXhr.status === 422 ) {
var errors = jqXhr.responseJSON;
ajaxValidate(form, formGroup, formGroupErrorDiv, btn, errors)
} else {
show_alert("Something went wrong. Please report to IRIS Team.", 'error');
}
}
});
return false;
});
});
</script>