mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-21 03:14:52 +02:00
Added an basic TextConstraint for part filtering.
This commit is contained in:
parent
f6239dfd50
commit
f8562f9622
9 changed files with 234 additions and 7 deletions
|
@ -32,6 +32,7 @@ class NumberConstraintType extends AbstractType
|
|||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$choices = [
|
||||
'' => '',
|
||||
'=' => '=',
|
||||
'!=' => '!=',
|
||||
'<' => '<',
|
||||
|
@ -68,6 +69,7 @@ class NumberConstraintType extends AbstractType
|
|||
$builder->add('operator', ChoiceType::class, [
|
||||
'label' => 'filter.number_constraint.operator',
|
||||
'choices' => $choices,
|
||||
'required' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
60
src/Form/Filters/Constraints/TextConstraintType.php
Normal file
60
src/Form/Filters/Constraints/TextConstraintType.php
Normal file
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
|
||||
namespace App\Form\Filters\Constraints;
|
||||
|
||||
use App\DataTables\Filters\Constraints\TextConstraint;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\NumberType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SearchType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class TextConstraintType extends AbstractType
|
||||
{
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'compound' => true,
|
||||
'data_class' => TextConstraint::class,
|
||||
'text_suffix' => '', // An suffix which is attached as text-append to the input group. This can for example be used for units
|
||||
]);
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$choices = [
|
||||
'' => '',
|
||||
'=' => '=',
|
||||
'!=' => '!=',
|
||||
'STARTS' => 'STARTS',
|
||||
'ENDS' => 'ENDS',
|
||||
'CONTAINS' => 'CONTAINS',
|
||||
'LIKE' => 'LIKE',
|
||||
'REGEX' => 'REGEX',
|
||||
];
|
||||
|
||||
$builder->add('value', SearchType::class, [
|
||||
'attr' => [
|
||||
'placeholder' => 'filter.text_constraint.value',
|
||||
],
|
||||
'required' => false,
|
||||
]);
|
||||
|
||||
|
||||
$builder->add('operator', ChoiceType::class, [
|
||||
'label' => 'filter.text_constraint.operator',
|
||||
'choices' => $choices,
|
||||
'required' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
public function buildView(FormView $view, FormInterface $form, array $options)
|
||||
{
|
||||
parent::buildView($view, $form, $options);
|
||||
|
||||
$view->vars['text_suffix'] = $options['text_suffix'];
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@ namespace App\Form\Filters;
|
|||
use App\DataTables\Filters\PartFilter;
|
||||
use App\Form\Filters\Constraints\BooleanConstraintType;
|
||||
use App\Form\Filters\Constraints\NumberConstraintType;
|
||||
use App\Form\Filters\Constraints\TextConstraintType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
@ -38,6 +39,14 @@ class PartFilterType extends AbstractType
|
|||
'min' => 0,
|
||||
]);
|
||||
|
||||
$builder->add('name', TextConstraintType::class, [
|
||||
'label' => 'part.edit.name',
|
||||
]);
|
||||
|
||||
$builder->add('description', TextConstraintType::class, [
|
||||
'label' => 'part.edit.description',
|
||||
]);
|
||||
|
||||
$builder->add('submit', SubmitType::class, [
|
||||
'label' => 'Update',
|
||||
]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue