mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-16 13:24:31 +02:00
Added some constraints and validations to the BOM entries.
This commit is contained in:
parent
4e3cad577e
commit
b83b55b8d4
6 changed files with 99 additions and 10 deletions
|
@ -5,12 +5,15 @@ namespace App\Form\ProjectSystem;
|
|||
use App\Entity\Parts\Part;
|
||||
use App\Entity\ProjectSystem\ProjectBOMEntry;
|
||||
use App\Form\Type\PartSelectType;
|
||||
use App\Form\Type\SIUnitType;
|
||||
use Svg\Tag\Text;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Event\PreSetDataEvent;
|
||||
use Symfony\Component\Form\Extension\Core\Type\NumberType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormEvents;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class ProjectBOMEntryType extends AbstractType
|
||||
|
@ -18,11 +21,20 @@ class ProjectBOMEntryType extends AbstractType
|
|||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
|
||||
->add('quantity', NumberType::class, [
|
||||
|
||||
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (PreSetDataEvent $event) {
|
||||
$form = $event->getForm();
|
||||
/** @var ProjectBOMEntry $data */
|
||||
$data = $event->getData();
|
||||
|
||||
$form->add('quantity', SIUnitType::class, [
|
||||
'label' => 'project.bom.quantity',
|
||||
])
|
||||
'measurement_unit' => $data && $data->getPart() ? $data->getPart()->getPartUnit() : null,
|
||||
]);
|
||||
});
|
||||
|
||||
$builder
|
||||
|
||||
->add('part', PartSelectType::class, [
|
||||
'required' => false,
|
||||
|
@ -31,7 +43,6 @@ class ProjectBOMEntryType extends AbstractType
|
|||
->add('name', TextType::class, [
|
||||
'label' => 'project.bom.name',
|
||||
'required' => false,
|
||||
'empty_data' => ''
|
||||
])
|
||||
->add('mountnames', TextType::class, [
|
||||
'required' => false,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue