136 lines
5.3 KiB
PHP
136 lines
5.3 KiB
PHP
|
|
@extends('template.template')
|
|
|
|
@section('title', 'Dashboard')
|
|
|
|
@section('content')
|
|
<div class="card shadow-sm">
|
|
<div class="card-header">
|
|
<h3 class="card-title">TAMBAH ASURANSI</h3>
|
|
<div class="card-toolbar gap-2">
|
|
<a href="{{ url('/asuransi') }}" class="btn btn-danger">Back</a>
|
|
</div>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="row d-flex justify-content-center">
|
|
<div class="col-md-8">
|
|
<form action="" id="form">
|
|
<div class="fv-row mb-10">
|
|
<label for="name" class="required form-label">Nama Asuransi</label>
|
|
<input type="text" name="name" id="name" class="form-control"
|
|
placeholder="Nama Asuransi" />
|
|
</div>
|
|
<div class="d-flex justify-content-end">
|
|
<button id="submit" class="btn btn-success">
|
|
<span class="indicator-label">
|
|
Submit
|
|
</span>
|
|
<span class="indicator-progress">
|
|
Please wait... <span class="spinner-border spinner-border-sm align-middle ms-2"></span>
|
|
</span>
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
@endsection
|
|
|
|
@section('custom_js')
|
|
<script>
|
|
let validator = null;
|
|
|
|
$(document).ready(function() {
|
|
const form = document.getElementById('form');
|
|
|
|
validator = FormValidation.formValidation(
|
|
form, {
|
|
fields: {
|
|
'name': {
|
|
validators: {
|
|
notEmpty: {
|
|
message: 'Name is required'
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
plugins: {
|
|
trigger: new FormValidation.plugins.Trigger(),
|
|
bootstrap: new FormValidation.plugins.Bootstrap5({
|
|
rowSelector: '.fv-row',
|
|
eleInvalidClass: '',
|
|
eleValidClass: ''
|
|
})
|
|
}
|
|
}
|
|
);
|
|
|
|
$('#submit').click(function(e) {
|
|
e.preventDefault();
|
|
submit();
|
|
});
|
|
});
|
|
|
|
function numericOnly(el){
|
|
el.value = el.value.replace(/[^0-9]/g, "");
|
|
}
|
|
|
|
function submit() {
|
|
if (validator) {
|
|
validator.validate().then(function(status) {
|
|
if (status == 'Valid') {
|
|
$('#submit').attr("data-kt-indicator", "on");
|
|
$('#submit').attr("disabled", "true");
|
|
|
|
const name = $('#name').val();
|
|
|
|
const data = {
|
|
name : name,
|
|
_token: "{{ csrf_token() }}"
|
|
}
|
|
$.ajax({
|
|
url: "{{ url('/asuransi/store') }}",
|
|
type: "POST",
|
|
data: data,
|
|
dataType: 'JSON',
|
|
success: function(response) {
|
|
if (response.status) {
|
|
Swal.fire({
|
|
icon: "success",
|
|
text: "Data Berhasil Disimpan",
|
|
buttonsStyling: false,
|
|
confirmButtonText: "close",
|
|
customClass: {
|
|
confirmButton: "btn btn-danger"
|
|
}
|
|
}).then(() => {
|
|
window.location.href = "{{ url('/asuransi') }}";
|
|
});
|
|
}
|
|
},
|
|
error: function(xhr) {
|
|
var errorMessage = xhr.responseJSON ? xhr.responseJSON.msg : "Terjadi kesalahan!";
|
|
Swal.fire({
|
|
icon: "error",
|
|
text: errorMessage,
|
|
buttonsStyling: false,
|
|
confirmButtonText: "Close",
|
|
customClass: {
|
|
confirmButton: "btn btn-danger"
|
|
}
|
|
});
|
|
},
|
|
complete: function() {
|
|
$('#submit').removeAttr("data-kt-indicator");
|
|
$('#submit').removeAttr("disabled");
|
|
}
|
|
});
|
|
}
|
|
});
|
|
}
|
|
}
|
|
</script>
|
|
@endsection
|