adopted-ember-addons / adopted-ember-addons/ember-changeset-validations

Feature request - sequential validations

Aperta
#278 8 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
JavaScript
Stelle
215
Fork
98
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

Using #220 as inspiration, I'm frequently using this custom validator in my code:

```js
export default function validateChain(validators) {
return async (key, value, oldValue, changes, content) => {
let result;
let index = 0;

do {
let validator = validators[index++];
result = await validator(key, value, oldValue, changes, content);
} while (true === result && index < validators.length);

return result;
};
}
```

My use case is exactly the same as the linked issue - I have expensive async custom validators that there's no point calling if other validators fail. Example use case:

```js
import {
validatePresence,
validateFormat
} from 'ember-changeset-validations/validators';
import validateChain from '../validators/chain';
import validateUniqueEmail from '../validators/unique-email';

export default {
email: validateChain([
validatePresence(true),
validateFormat({ type: 'email' }),
validateUniqueEmail(),
]),
};
```

I think this sequential validator is really useful as this use case is common. So my question is - would you accept a PR adding it to this package?

If yes, then two questions:

1. What would you like the validator to be called?
2. How should I be checking for object validators? Just checking for the existence of a validate function?

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.