Skip to content

Commit

Permalink
Merge pull request #9332 from shoosah/feature/add-error-message-into-…
Browse files Browse the repository at this point in the history
…field

Allow to add error message into a specific field
  • Loading branch information
bergice authored May 1, 2020
2 parents ec51f98 + 2724d93 commit 3a42474
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Forms/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -1274,6 +1274,23 @@ public function sessionError($message, $type = ValidationResult::TYPE_ERROR, $ca
$this->setSessionValidationResult($result);
}

/**
* Set an error message for a field in the session, for display next time this form is shown.
*
* @param string $message the text of the message
* @param string $fieldName Name of the field to set the error message on it.
* @param string $type Should be set to good, bad, or warning.
* @param string|bool $cast Cast type; One of the CAST_ constant definitions.
* Bool values will be treated as plain text flag.
*/
public function sessionFieldError($message, $fieldName, $type = ValidationResult::TYPE_ERROR, $cast = ValidationResult::CAST_TEXT)
{
$this->setMessage($message, $type, $cast);
$result = $this->getSessionValidationResult() ?: ValidationResult::create();
$result->addFieldMessage($fieldName, $message, $type, null, $cast);
$this->setSessionValidationResult($result);
}

/**
* Returns the DataObject that has given this form its data
* through {@link loadDataFrom()}.
Expand Down

0 comments on commit 3a42474

Please sign in to comment.