dandean/express-form — Issue #26: validate.require() won't work well for filter.trim() if data spaced
Author: reekoheek
Created: 2011-12-18 11:15:06+00:00
State: open

I used configuration as follows:

```javascript
var form = require('express-form').configure({
autoTrim: true,
passThrough: true,
autoLocals: false,
dataSources: ['body']
});
```

and rules as follows:

```javascript
form(
filter('url').trim(),
validate('url', 'URL').required()
)
```

I'm expecting data will be trimmed first and then the trimmed data will be validated.
When I input spaced string only (ex: ' ' ), it won't goes error (should be error because it is empty string)

I check the code and found at lib/field.js line 35

``` javascript
property = property.replace(/\[((.)*?)\]/g, ".$1"); // Convert square-bracket to dot notation.

var value = utils.getProp(property, form) || utils.getProp(property, source);
```

the value to evaluated gotten from "form" (which is the right ones) or if it is empty gotten from "source" (its bad cause, trim will make valid input empty string but you take the original from source to evaluate.

My workaround is:

```javascript
property = property.replace(/\[((.)*?)\]/g, ".$1"); // Convert square-bracket to dot notation.

// REMARK by reekoheek: I disabled utils.getProp(property, source)
// and leave it to 'form' alone to validate
// as I use configuration "passThrough = true"
// var value = utils.getProp(property, form) || utils.getProp(property, source);
var value = utils.getProp(property, form); // || utils.getProp(property, source);
```

I hope it will help you, because it takes me hours to search documentations but cannot found about it :)