mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-19 10:24:50 +02:00
Allow to filter parameters based on their text value
This commit is contained in:
parent
9ed953d1b2
commit
bc0365fe16
4 changed files with 78 additions and 10 deletions
|
@ -8,6 +8,8 @@ use Symfony\Component\Form\AbstractType;
|
|||
use Symfony\Component\Form\Extension\Core\Type\SearchType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormEvent;
|
||||
use Symfony\Component\Form\FormEvents;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class ParameterConstraintType extends AbstractType
|
||||
|
@ -17,6 +19,7 @@ class ParameterConstraintType extends AbstractType
|
|||
$resolver->setDefaults([
|
||||
'compound' => true,
|
||||
'data_class' => ParameterConstraint::class,
|
||||
'empty_data' => new ParameterConstraint(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -31,7 +34,26 @@ class ParameterConstraintType extends AbstractType
|
|||
]);
|
||||
|
||||
$builder->add('symbol', SearchType::class, [
|
||||
'required' => false
|
||||
'required' => false
|
||||
]);
|
||||
|
||||
$builder->add('value_text', TextConstraintType::class, [
|
||||
//'required' => false,
|
||||
] );
|
||||
|
||||
/*
|
||||
* I am not quite sure why this is needed, but somehow symfony tries to create a new instance of TextConstraint
|
||||
* instead of using the existing one for the prototype (or the one from empty data). This fails as the constructor of TextConstraint requires
|
||||
* arguments.
|
||||
* Ensure that the data is never null, but use an empty ParameterConstraint instead
|
||||
*/
|
||||
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
|
||||
$form = $event->getForm();
|
||||
$data = $event->getData();
|
||||
|
||||
if ($data === null) {
|
||||
$event->setData(new ParameterConstraint());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Form\Filters;
|
||||
|
||||
use App\DataTables\Filters\Constraints\Part\ParameterConstraint;
|
||||
use App\DataTables\Filters\PartFilter;
|
||||
use App\Entity\Attachments\AttachmentType;
|
||||
use App\Entity\Parts\Category;
|
||||
|
@ -211,12 +212,16 @@ class PartFilterType extends AbstractType
|
|||
'label' => 'part.filter.attachmentName',
|
||||
]);
|
||||
|
||||
$constraint_prototype = new ParameterConstraint();
|
||||
|
||||
$builder->add('parameters', CollectionType::class, [
|
||||
'label' => 'parameter.label',
|
||||
'entry_type' => ParameterConstraintType::class,
|
||||
'allow_delete' => true,
|
||||
'allow_add' => true,
|
||||
'reindex_enable' => false,
|
||||
'prototype_data' => $constraint_prototype,
|
||||
'empty_data' => $constraint_prototype,
|
||||
]);
|
||||
|
||||
$builder->add('submit', SubmitType::class, [
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue