aurelia / aurelia/validation

Dynamic validation error messages

Open
#473 6 comments 2 reactions 0 assignees View on GitHub
question
Dominant language
TypeScript
Stars
129
Forks
125
PR merge metrics
No merged PRs in 30d

Description

**I'm submitting a feature request**

Currently, it is impossible to create a dynamic validation error message. For example, I want to validate IBAN account number. I configure the rule as follows:

```
ValidationRules
.ensure('account').displayName("Account number")
.satisfies(account => getActualChecksum(account) == calculateChecksum(account))
.withMessage("Given IBAN number is invalid");
```

The validation message could be much more informative, for example `Given IBAN number has cheksum 34 but it should be 56`.

What about allowing to pass a callback that will generate a validation message based on given value? This should solve all of the cases where the validation message should be built based on the given value or something else dynamic.

```
ValidationRules
.ensure('account').displayName("Account number")
.satisfies(account => getActualChecksum(account) == calculateChecksum(account))
.withMessage(account => "Given IBAN has checksum " + getActualChecksum(account) + " but it should be " +calculateChecksum(account));
```

OR it should be possible to define special parameters for message in addition to existing `$displayName` and `$value`, e.g.

```
ValidationRules
.ensure('account').displayName("Account number")
.satisfies(account => getActualChecksum(account) == calculateChecksum(account))
.withMessage("Given IBAN has checksum ${actualChecksum} but it should be ${correctChecksum}")
.withMessageParamsBuilder(account => {actualChecksum: getActualChecksum(account), correctChecksum: calculateChecksum(account)});
```

What do you think?

Contributor guide

Open the contributing guide

Research direction

The issue names no files, tests, or entry points. Start by tracing the existing withMessage handling and the current $displayName and $value parameters, then determine which dynamic-message approach the project should support. Done means the chosen API is implemented with coverage for values that produce dynamic validation text.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.