adopted-ember-addons / adopted-ember-addons/ember-changeset-validations
Feature request - sequential validations
- Linguagem predominante
- JavaScript
- Estrelas
- 215
- Forks
- 98
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Descrição
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?
Guia de contribuição
Avaliação
Esta issue ainda não foi avaliada.