Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]symfony4 - Formularz, pole wymagane
kamil_lk
post 18.04.2019, 11:31:27
Post #1





Grupa: Zarejestrowani
Postów: 325
Pomógł: 33
Dołączył: 31.05.2008

Ostrzeżenie: (0%)
-----


Cześć.
Jak w symfony 4 uzależnić jedno pole od drugiego.

Mam encję example
  1. #src/Entity/Example.php
  2.  
  3. <?php
  4.  
  5. namespace App\Entity;
  6.  
  7. class Example
  8. {
  9.  
  10. private $id;
  11.  
  12. /**
  13.   * @Assert\NotBlank
  14.   */
  15. private $key;
  16.  
  17. private $value;
  18.  
  19. public function getKey(): ?int
  20. {
  21. return $this->key;
  22. }
  23.  
  24. public function setKey(int $key): self
  25. {
  26. $this->key = $key;
  27.  
  28. return $this;
  29. }
  30.  
  31. public function getValue(): ?int
  32. {
  33. return $this->value;
  34. }
  35.  
  36. public function setValue(int $value): self
  37. {
  38. $this->value = $value;
  39.  
  40. return $this;
  41. }
  42.  
  43. }


Z takiej encji buduję formularz
  1. public function buildForm(FormBuilderInterface $builder, array $options): void
  2. {
  3. $builder
  4. ->add('key', IntegerType::class)
  5. ->add('value', IntegerType::class);
  6.  
  7. }


W jaki sposób ustawić walidację na pole value, tylko wtedy gdy pole key ma wartość 1
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 24.04.2024 - 12:24