Fix batch EDA edit: required validation and pre-populate shared values

- Add required=false to TriStateCheckboxType fields so HTML5 validation
  doesn't force users to check visibility/BOM/board checkboxes
- Pre-populate form fields when all selected parts share the same EDA
  value, so users can see current state before editing
This commit is contained in:
Sebastian Almberg 2026-02-10 21:10:55 +01:00
parent 310872b7a5
commit 59e36fb824
2 changed files with 37 additions and 1 deletions

View file

@ -18,6 +18,36 @@ class BatchEdaController extends AbstractController
{ {
} }
/**
* Compute shared EDA values across all parts. If all parts have the same value for a field, return it.
* @param Part[] $parts
* @return array<string, mixed>
*/
private function getSharedEdaValues(array $parts): array
{
$fields = [
'reference_prefix' => static fn (Part $p) => $p->getEdaInfo()->getReferencePrefix(),
'value' => static fn (Part $p) => $p->getEdaInfo()->getValue(),
'kicad_symbol' => static fn (Part $p) => $p->getEdaInfo()->getKicadSymbol(),
'kicad_footprint' => static fn (Part $p) => $p->getEdaInfo()->getKicadFootprint(),
'visibility' => static fn (Part $p) => $p->getEdaInfo()->getVisibility(),
'exclude_from_bom' => static fn (Part $p) => $p->getEdaInfo()->getExcludeFromBom(),
'exclude_from_board' => static fn (Part $p) => $p->getEdaInfo()->getExcludeFromBoard(),
'exclude_from_sim' => static fn (Part $p) => $p->getEdaInfo()->getExcludeFromSim(),
];
$data = [];
foreach ($fields as $key => $getter) {
$values = array_map($getter, $parts);
$unique = array_unique($values, SORT_REGULAR);
if (count($unique) === 1) {
$data[$key] = $unique[array_key_first($unique)];
}
}
return $data;
}
#[Route('/tools/batch_eda_edit', name: 'batch_eda_edit')] #[Route('/tools/batch_eda_edit', name: 'batch_eda_edit')]
public function batchEdaEdit(Request $request): Response public function batchEdaEdit(Request $request): Response
{ {
@ -36,7 +66,9 @@ class BatchEdaController extends AbstractController
return $redirectUrl !== '' ? $this->redirect($redirectUrl) : $this->redirectToRoute('parts_show_all'); return $redirectUrl !== '' ? $this->redirect($redirectUrl) : $this->redirectToRoute('parts_show_all');
} }
$form = $this->createForm(BatchEdaType::class); //Pre-populate form with shared values (when all parts have the same value)
$initialData = $this->getSharedEdaValues($parts);
$form = $this->createForm(BatchEdaType::class, $initialData);
$form->handleRequest($request); $form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {

View file

@ -67,6 +67,7 @@ class BatchEdaType extends AbstractType
]) ])
->add('visibility', TriStateCheckboxType::class, [ ->add('visibility', TriStateCheckboxType::class, [
'label' => 'eda_info.visibility', 'label' => 'eda_info.visibility',
'required' => false,
]) ])
->add('apply_visibility', CheckboxType::class, [ ->add('apply_visibility', CheckboxType::class, [
'label' => 'batch_eda.apply', 'label' => 'batch_eda.apply',
@ -75,6 +76,7 @@ class BatchEdaType extends AbstractType
]) ])
->add('exclude_from_bom', TriStateCheckboxType::class, [ ->add('exclude_from_bom', TriStateCheckboxType::class, [
'label' => 'eda_info.exclude_from_bom', 'label' => 'eda_info.exclude_from_bom',
'required' => false,
]) ])
->add('apply_exclude_from_bom', CheckboxType::class, [ ->add('apply_exclude_from_bom', CheckboxType::class, [
'label' => 'batch_eda.apply', 'label' => 'batch_eda.apply',
@ -83,6 +85,7 @@ class BatchEdaType extends AbstractType
]) ])
->add('exclude_from_board', TriStateCheckboxType::class, [ ->add('exclude_from_board', TriStateCheckboxType::class, [
'label' => 'eda_info.exclude_from_board', 'label' => 'eda_info.exclude_from_board',
'required' => false,
]) ])
->add('apply_exclude_from_board', CheckboxType::class, [ ->add('apply_exclude_from_board', CheckboxType::class, [
'label' => 'batch_eda.apply', 'label' => 'batch_eda.apply',
@ -91,6 +94,7 @@ class BatchEdaType extends AbstractType
]) ])
->add('exclude_from_sim', TriStateCheckboxType::class, [ ->add('exclude_from_sim', TriStateCheckboxType::class, [
'label' => 'eda_info.exclude_from_sim', 'label' => 'eda_info.exclude_from_sim',
'required' => false,
]) ])
->add('apply_exclude_from_sim', CheckboxType::class, [ ->add('apply_exclude_from_sim', CheckboxType::class, [
'label' => 'batch_eda.apply', 'label' => 'batch_eda.apply',