Disable past dates in Bootstrap datetimepicker

323 Views Asked by At

I have application in Laravel where I use bootstrap Datetimepicker.

I want to disable all past dates in datetimepicker.

The input datetimepicker was in the modal by the way.

This is my blade code

<div id="request_leave" class="modal custom-modal fade" role="dialog">
        <div class="modal-dialog modal-dialog-centered" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">Request Leave</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <form action="{{ route('LeaveSave') }}" method="POST">
                        @csrf
                        <div class="form-group">
                            <label>Leave Type <span class="text-danger">*</span></label>
                            <select class="select @error('leave_type') is-invalid @enderror" id="leave_type" name="leave_type">
                                <option selected disabled> --Select-- </option>
                                <option value="Vacation Leave">Vacation Leave</option>
                                <option value="Sick Leave">Sick Leave</option>
                                <option value="Indefinite Leave">Indefinite Leave</option>
                            </select>
                            @error('leave_type')
                            <span class="invalid-feedback" role="alert">
                                <strong>{{ $message }}</strong>
                            </span>
                            @enderror
                        </div>
                        <input type="hidden" class="form-control" id="rec_id" name="rec_id" value="{{ Auth::user()->rec_id }}">
                        <div class="form-group">
                            <label>From <span class="text-danger">*</span></label>
                            <div class="cal-icon">
                                <input type="text" class="form-control datetimepicker @error('from_date') is-invalid @enderror" id="from_date" name="from_date">
                                @error('from_date')
                                <span class="invalid-feedback" role="alert">
                                    <strong>{{ $message }}</strong>
                                </span>
                                @enderror
                            </div>
                        </div>

I get this code from internet but it's not working.

    <script>
    $(document).ready(function()
    {
        $('#from_date').datepicker({
            changeMonth: true,
            changeYear:true,
            showButtonPanel: true,
            minDate: new Date(),
        });
    })
</script>
0

There are 0 best solutions below