sertificate_edit.blade.php 3.41 KB
@extends('workers.cabinet_layout', ['title' => 'Редактирование стандартного документа - РекаМоре'])

@section('cabinet_content')
<h3 class="cabinet__h4 font30">Сертификат / документ</h3>
<form id="submit_form" name="submit_form" action="{{ route('worker.update_serificate', ['doc' => $doc->id]) }}" class="cabinet__inputs" method="GET">
    @csrf
    <input type="hidden" name="worker_id" id="worker_id" class="input" value="{{ $worker->id }}">

    <div class="cabinet__body-item width100">
        <div class="cabinet__inputs sertificate-form-inputs">
            <div class="cabinet__inputs-item form-group">
                <label class="form-group__label">Название сертификата:</label>
                <div class="form-group__item">
                    @error('name')
                    <div class="error red">{{ $message }}</div>
                    @enderror
                    <input type="text" name="name" id="name" class="input" value="{{ old('name') ?? $doc->name }}">
                </div>
            </div>
            <div class="cabinet__inputs-item form-group">
                <label class="form-group__label">Действия сертификата до:</label>
                <div class="form-group__item">
                    @error('end_begin')
                    <div class="error red">{{ $message }}</div>
                    @enderror
                    <input
                        type="text"
                        name="end_begin"
                        id="end_begin"
                        class="input"
                        placeholder="11.11.2011"
                        value="{{ old('end_begin') ?? date('d.m.Y', strtotime($doc->end_begin)) }}">
                </div>
            </div>
        </div>
    </div>

    <div class="flex">
        <button type="submit" class="button mr-10">Сохранить</button>
        <a href="{{ route('worker.cabinet') }}" class="button button_light">Назад</a>
    </div>
</form>
@endsection

@section('scripts')

    <script>
        $('#submit_form').on('submit', function (event) {
            event.preventDefault();
            var form = $(this);
            var isValid = true;

            form.find('.error-block').remove();
            form.find('input').removeClass('border-red');

            var name = form.find('[name="name"]').val().trim();
            if (!name) {
                form.find('[name="name"]').addClass('border-red');
                isValid = false;
            }

            var endDate = form.find('[name="end_begin"]').val().trim();
            var dateFormatRegex = /^\d{2}\.\d{2}\.\d{4}$/;
            if (!endDate) {
                form.find('[name="end_begin"]').addClass('border-red');
                form.find('[name="end_begin"]').after('<span class="error-block">Поле "Действия сертификата до" обязательно для заполнения.</span>');
                isValid = false;
            } else if (!dateFormatRegex.test(endDate)) {
                form.find('[name="end_begin"]').addClass('border-red');
                form.find('[name="end_begin"]').after('<span class="error-block">Неверный формат даты (дд.мм.гггг).</span>');
                isValid = false;
            }

            if (isValid) {
                form.off('submit').submit();
            }
        });

    </script>
@endsection