Search code examples
phpbundlesymfony

LexikFormFilterBundle select multiple dates


I would like to have a filter for several dates, for example a whole week of a whole month. I have tried severals ways to do it but noone succeded. I am not very used to this bundle and I don't find the way to select correctly my dates.

    $builder->add('receptionCommande', DateFilterType::class, array(
        'widget'    => 'text',
        'required'  => false,
        'format'    => 'dd / MM / yyyy',
        'input'     => 'string',
        'attr'      => array('day' => '%'),
        'days'      => array('data' => '%')
    ));

I was trying here to put a joker value on days.

    $builder->add('receptionCommande', TextFilterType::class, array(
        'data_class'     => 'year'
    ));

Here I wanted to select only the year of the date, but this didn't succeded. I'm struggeling with this for hours. Does anyone knows how to do, or even have a hint to guide me ?


Solution

  • I suggest you to use the filter_date_range Type that help you select a date interval.

    As example:

        $builder->add('receptionCommande', DateRangeFilterType::class, array(
         'left_date_options' => array(
            'attr' => array('class' => 'datepicker'),
            'widget'    => 'single_text',
            ),
         'right_date_options' => array(
            'attr' => array('class' => 'datepicker'),
            'widget'    => 'single_text',
            ),
         'label' => 'A Range of date',
         ));
    

    Hope this help