Skip to content

Commit

Permalink
add simple DateRangeType for filters
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrombez committed Sep 21, 2023
1 parent 05d6644 commit 9d5416b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Dto/DateRange
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Kibatic\DatagridBundle\Dto;

class DateRange
{
public ?\DateTimeInterface $start;
public ?\DateTimeInterface $end;
}
35 changes: 35 additions & 0 deletions src/Form/DateRangeType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Kibatic\DatagridBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Kibatic\DatagridBundle\Dto\DateRange;

class DateRangeType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('start', DateType::class, [
'label' => 'From',
'widget' => 'single_text',
'required' => false,
])
->add('end', DateType::class, [
'label' => 'To',
'widget' => 'single_text',
'required' => false,
])
;
}

public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => DateRange::class,
]);
}
}

0 comments on commit 9d5416b

Please sign in to comment.