Problem with validation and custom messages.
- Langage dominant
- JavaScript
- Étoiles
- 2k
- Forks
- 238
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
Sparked by [this issue on StackOverflow](http://stackoverflow.com/questions/15541154/customize-validation-message-in-node-js) I created the following testcase:
``` js
var juggling = require('jugglingdb');
var Schema = juggling.Schema;
var schema = new Schema('memory');
var User = schema.define('User');
var num = /^\s*\d+\s*$/;
User.validatesPresenceOf('id', {message: "can't be blank"});
User.validatesFormatOf('id', {with: num, message:"is not a number"});
User.validatesFormatOf('id', {with: num, message:"is not a number"}); // yes, twice
var user = new User({ id : '' });
user.isValid(function(valid) {
if (! valid)
{
console.log('invalid', user.errors);
}
else
{
console.log('valid');
}
});
```
This generates three errors:
```
invalid { id: [ 'can\'t be blank', 'is blank', 'is blank' ] }
```
The 2 `is blank` messages are incorrect (it's the default message for `validatesPresenceOf`), and it looks like there might be a scoping issue somewhere in the validation code. It also happens with only one `validatesFormatOf`, by the way.
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Piste de recherche
Look at the validation code in the jugglingdb source, likely in a file like lib/validations.js or similar. The test case shows a scoping issue where custom messages for validatesFormatOf are being overridden by the default message from validatesPresenceOf. Start by tracing where validation errors are collected and how message overrides are handled. Run the provided test to reproduce the error, then examine the flow for validatesFormatOf and validatesPresenceOf to see where the message gets lost.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- javascript, nodejs
- Domaine
- backend, databases
- Type d'issue
- Bug
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Activité
- À l'abandon
- Clarté
- Clairement spécifiée
- Accessibilité débutants
- 45/100