yaroslavche/symfony-ux-flatpickr

Flatpickr integration for Symfony

dev-main 2023-09-13 19:16 UTC

This package is auto-updated.

Last update: 2024-12-13 22:23:18 UTC


README

$ composer require yaroslavche/symfony-ux-flatpickr
$ yarn install --force
$ yarn encore dev
# src/Controller/SomeController.php
# ...
use Yaroslavche\Symfony\UX\Flatpickr\Form\Type\FlatpickrDateTimeType;
use Yaroslavche\Symfony\UX\Flatpickr\Form\Type\FlatpickrDateType;

class SomeController extends AbstractController
{
    /**
     * @Route("/", name="home")
     * @param Request $request
     * @return Response
     */
    public function index(Request $request): Response
    {
        $form = $this->createFormBuilder()
            ->add('date', FlatpickrDateType::class)
            ->add('datetime', FlatpickrDateTimeType::class)
            ->add('send', SubmitType::class)
            ->getForm();
        $form->handleRequest($request);
        if ($form->isSubmitted() && $form->isValid()) {
            $data = $form->getData();
            dd($data);
        }
        return $this->renderForm('template.html.twig', ['form' => $form]);
    }
}

Installation without recipe

  # assets/controllers.json
  "controllers": {
        "@yaroslavche/symfony-ux-flatpickr": {
            "flatpickr": {
                "enabled": true,
                "fetch": "eager"
            }
        }
    },
# package.json
"devDependencies": {
  # ...
  "@yaroslavche/symfony-ux-flatpickr": "file:vendor/yaroslavche/symfony-ux-flatpickr/src/Resources/assets",
  "flatpickr": "^4.6.13"          
}

Make sure, that you have in package.json

"@symfony/stimulus-bridge": "^3.2.2",
"@symfony/webpack-encore": "^4.0.0",

Upgrading to stimulus-bridge 2.0