fix validation when comment content is empty

This commit is contained in:
Julien Fastré 2022-02-07 20:53:44 +01:00
parent 03007370bc
commit b3e65f0733
4 changed files with 20 additions and 12 deletions

View File

@ -235,6 +235,8 @@ class NotificationController extends AbstractController
'id' => $notification->getId(),
'_fragment' => 'comment-' . $commentId,
]);
} elseif ($editedCommentForm->isSubmitted() && !$editedCommentForm->isValid()) {
$this->addFlash('error', $this->translator->trans('This form contains errors'));
}
}
}
@ -256,6 +258,8 @@ class NotificationController extends AbstractController
return $this->redirectToRoute('chill_main_notification_show', [
'id' => $notification->getId(),
]);
} elseif ($appendCommentForm->isSubmitted() && !$appendCommentForm->isValid()) {
$this->addFlash('error', $this->translator->trans('This form contains errors'));
}
}
}

View File

@ -18,6 +18,7 @@ use DateTimeInterface;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Event\PreFlushEventArgs;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity
@ -28,6 +29,7 @@ class NotificationComment implements TrackCreationInterface, TrackUpdateInterfac
{
/**
* @ORM\Column(type="text")
* @Assert\NotBlank(message="notification.Comment content might not be blank")
*/
private string $content = '';
@ -136,9 +138,9 @@ class NotificationComment implements TrackCreationInterface, TrackUpdateInterfac
$this->recentlyPersisted = true;
}
public function setContent(string $content): self
public function setContent(?string $content): self
{
$this->content = $content;
$this->content = (string) $content;
return $this;
}

View File

@ -32,6 +32,7 @@
{{ form_start(editedCommentForm) }}
{{ form_errors(editedCommentForm) }}
{{ form_widget(editedCommentForm.content) }}
{{ form_errors(editedCommentForm.content) }}
<input type="hidden" name="form" value="edit" />
<ul class="record_actions">
<li class="cancel">
@ -64,6 +65,7 @@
{{ form_start(appendCommentForm) }}
{{ form_errors(appendCommentForm) }}
{{ form_widget(appendCommentForm.content) }}
{{ form_errors(appendCommentForm.content) }}
<input type="hidden" name="form" value="append" />
<ul class="record_actions">
<li>

View File

@ -27,4 +27,4 @@ address:
notification:
At least one addressee: Indiquez au moins un destinataire
Title must be defined: Un titre doit être indiqué
Comment content might not be blank: Le commentaire ne peut pas être vide