Skip to content
Snippets Groups Projects
Commit 460fcdf5 authored by Si Hobbs's avatar Si Hobbs
Browse files

Fix constraints for non-required fields.

parent 48ab7947
No related branches found
No related tags found
1 merge request!2Optional end date as radios for future optional start date.
Pipeline #48476 failed
......@@ -165,19 +165,29 @@ public function getConstraints() {
->getValidationConstraintManager();
$constraints = parent::getConstraints();
if ($this->getSetting('optional_values') == static::OPTIONAL_END) {
return $constraints;
}
$label = $this->getFieldDefinition()->getLabel();
$constraints[] = $constraint_manager
->create('ComplexData', [
'end_value' => [
'NotNull' => [
'message' => $this->t('The @title end date is required', ['@title' => $label]),
if (!$this->getFieldDefinition()->isRequired()) {
$label = $this->getFieldDefinition()->getLabel();
// If the end date triggers constraint validation then test the start date.
$constraints[] = $constraint_manager
->create('ComplexData', [
'value' => [
'NotNull' => [
'message' => $this->t('The @title start date is required', ['@title' => $label]),
],
],
],
]);
]);
// Testing the end date is only needed if not required and not optional.
if ($this->getSetting('optional_values') == static::OPTIONAL_NONE) {
$constraints[] = $constraint_manager
->create('ComplexData', [
'end_value' => [
'NotNull' => [
'message' => $this->t('The @title end date is required', ['@title' => $label]),
],
],
]);
}
}
return $constraints;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment