Problem with validation and custom messages.
- Lingua principale
- JavaScript
- Stelle
- 2k
- Fork
- 238
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
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.
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript, nodejs
- Ambito
- backend, databases
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 45/100