32 lines
1.2 KiB
PHP
32 lines
1.2 KiB
PHP
@once
|
|
@push('scripts')
|
|
<script>
|
|
function initSaveForm(form, sel) {
|
|
if (typeof initValidator === 'function') {
|
|
initValidator();
|
|
}
|
|
var form = (typeof(form) == 'undefined') ? '#form' : form;
|
|
var selector = (typeof(sel) == 'undefined') ? '.save' : sel;
|
|
$(selector).off().click(function(e) {
|
|
if (typeof initValidator === 'function') {
|
|
e.preventDefault();
|
|
if ($(form).valid()) {
|
|
$(this).prop("disabled", true);
|
|
$(this).html($(this).data('loading-text'));
|
|
$(form).submit();
|
|
} else {
|
|
const $firstInvalid = $(form).find(':invalid, .error').first();
|
|
if ($firstInvalid.length) {
|
|
$firstInvalid.focus();
|
|
}
|
|
}
|
|
} else {
|
|
$(form).submit();
|
|
}
|
|
});
|
|
}
|
|
</script>
|
|
@endpush
|
|
@php(define('LOAD_SAVE', true))
|
|
@endonce
|