To use the jQueryDateTimePicker within the Livewire component for the dob and doh fields, you can follow these steps:
-
Install the jQueryDateTimePicker library if you haven't already. You can use npm or include it directly in your HTML file.
-
Add Livewire directives to the
dobanddohinput fields to enable Livewire's two-way data binding. -
Add a Livewire
wire:ignoredirective to thedobanddohinput fields to prevent Livewire from updating them. -
Add a Livewire
wire:ignoredirective to the script tag that initializes the datetimepickers to prevent Livewire from updating it. -
Create a Livewire method to handle the initialization of the datetimepickers.
Here's an example of how you can modify your code to achieve this:
<div class="row">
<div class="col-6">
<label class="form-label" for="doh">Date of Hire / Start</label>
<input type="text" id="doh" name="doh" placeholder="mm/dd/yyyy"
class="form-control @error('doh') is-invalid @enderror"
value="{{ $user->doh }}" wire:model="doh" wire:ignore>
@error('doh')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
<div class="col-6">
<label class="form-label" for="dob">Date of Birth</label>
<input type="text" id="dob" name="dob"
class="form-control @error('dob') is-invalid @enderror"
value="{{ $user->dob }}" wire:model="dob" wire:ignore>
@error('dob')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
</div>
@push('scripts')
<script>
document.addEventListener('livewire:load', function () {
initializeDateTimePickers();
});
function initializeDateTimePickers() {
$('#doh').datetimepicker({
value: new Date(),
mask: '99/99/9999 99:99',
timepicker: true,
format: 'm/d/Y H:i',
dayOfWeekStart: 1,
scrollMonth: false,
scrollTime: false,
scrollInput: false,
lang: 'en',
step: 10
});
$('#dob').datetimepicker({
value: null,
mask: '99/99/9999 99:99',
timepicker: true,
format: 'm/d/Y H:i',
dayOfWeekStart: 1,
scrollMonth: false,
scrollTime: false,
scrollInput: false,
lang: 'en',
step: 10
});
}
</script>
@endpush
Make sure to include the necessary JavaScript and CSS files for the jQueryDateTimePicker library in your HTML file.
Note: If you're using Laravel Mix or any other build tool, you may need to adjust the way you include the jQueryDateTimePicker library.