1 |
|
2 |
|
3 |
|
4 | 'use strict';
|
5 |
|
6 | const Base = require('../base/Behavior');
|
7 |
|
8 | module.exports = class TrimBehavior extends Base {
|
9 |
|
10 | constructor (config) {
|
11 | super({
|
12 |
|
13 | ...config
|
14 | });
|
15 | this.setHandler(ActiveRecord.EVENT_BEFORE_VALIDATE, this.beforeValidate);
|
16 | }
|
17 |
|
18 | beforeValidate () {
|
19 | for (const attr of this.attrs) {
|
20 | const value = this.owner.get(attr);
|
21 | if (value && typeof value === 'string') {
|
22 | this.owner.set(attr, value.trim());
|
23 | }
|
24 | }
|
25 | }
|
26 | };
|
27 |
|
28 | const ActiveRecord = require('../db/ActiveRecord'); |
\ | No newline at end of file |