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

Feature request - sequential validations

Abierto
#278 8 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
JavaScript
Estrellas
215
Forks
98
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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?

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.