feat: step input for room type selection
This commit is contained in:
@@ -4,7 +4,6 @@ namespace App\Form;
|
||||
|
||||
use App\Form\Model\RoomSelectionDto;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormEvent;
|
||||
@@ -28,9 +27,11 @@ class RoomSelectType extends AbstractType
|
||||
$label .= sprintf(' (€%s pro Person)', $formattedPrice);
|
||||
}
|
||||
|
||||
$form->add('quantity', ChoiceType::class, [
|
||||
$form->add('quantity', StepSelectChoiceType::class, [
|
||||
'label' => $label,
|
||||
'required' => true,
|
||||
'min_value' => 0,
|
||||
'max_value' => $data->maxQuantity,
|
||||
'choices' => ['-' => 0] + array_combine(range(1, $data->maxQuantity), range(1, $data->maxQuantity)),
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class StepSelectChoiceType extends AbstractType
|
||||
{
|
||||
public function getParent(): string
|
||||
{
|
||||
return ChoiceType::class;
|
||||
}
|
||||
|
||||
public function buildView(FormView $view, FormInterface $form, array $options): void
|
||||
{
|
||||
$view->vars['min_value'] = $options['min_value'];
|
||||
$view->vars['max_value'] = $options['max_value'];
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'min_value' => null,
|
||||
'max_value' => null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user