1 |
|
2 |
|
3 |
|
4 | 'use strict';
|
5 |
|
6 | const Base = require('./Validator');
|
7 |
|
8 | module.exports = class CheckboxValidator extends Base {
|
9 |
|
10 | constructor (config) {
|
11 | super({
|
12 | skipOnEmpty: false,
|
13 | ...config
|
14 | });
|
15 | }
|
16 |
|
17 | getMessage () {
|
18 | return this.createMessage(this.message, 'Invalid value');
|
19 | }
|
20 |
|
21 | validateAttr (attr, model) {
|
22 | const value = model.get(attr);
|
23 | if (typeof value === 'boolean' ) {
|
24 | return true;
|
25 | }
|
26 | const trueValue = value === 'true' || value === 'on';
|
27 | if (value && value !== 'false' && !trueValue) {
|
28 | return this.getMessage();
|
29 | }
|
30 | model.set(attr, trueValue);
|
31 | }
|
32 | }; |
\ | No newline at end of file |