Or nobody using pikaday now? Maybe that's getting old? And other script suggestion?
Dec 27, 2022
7
Level 4
Pikaday / Moment / Alpinejs, moment script import
Hi all!
I'm stuck with the correct way to import Moment on a pikaday field to format my field. I'm following the tutorial from the livewire screencast serie, but I import the scripts using node.
For now: pikaday is working, but I don't know how to import / init moment to format my date.
Here is my code:
@props(['disabled' => false])
<div x-data x-init="new Pikaday({ field: $refs.input, format:'M/D/YY' })">
<input x-ref="input" {{ $disabled ? 'disabled' : '' }} {!! $attributes->merge(['class' => 'block w-full']) !!}>
</div>
import Pikaday from 'pikaday';
window.Pikaday = Pikaday;
(css is imported directely in the styles)
How to import moment? tried this way, it's not working. My formatting value is in the blade view format:'M/D/YY'.
import moment from 'moment';
window.moment = moment;
Thank you in advance,
Level 51
I think the order ended up mattering for me.
import Alpine from 'alpinejs';
import moment from "moment";
window.moment = moment;
window.Alpine = Alpine;
Alpine.start();
// and in then for pikaday...
toString(date) { return window.moment(date).format('ddd, MMM D, YYYY') } }
Please or to participate in this conversation.