|
39 | 39 | match: (el, regexp) => regexp.test(el.val()), |
40 | 40 | mismatch: (el, regexp) => !regexp.test(el.val()), |
41 | 41 | not: (el, value) => el.val() != value, |
42 | | - not_blank: el => el.val().trim(), |
43 | | - not_checked: el => !el.is(':checked') |
| 42 | + not_blank: el => !CONDITIONS.blank(el), |
| 43 | + not_checked: el => !CONDITIONS.checked(el) |
44 | 44 | } |
45 | 45 |
|
46 | 46 | const REVERSE_ACTIONS = { |
|
53 | 53 | slide: el => el.slideDown() |
54 | 54 | } |
55 | 55 |
|
| 56 | + const REGEXP_NOT = /^!\s*/ |
| 57 | + |
56 | 58 | class Field { |
57 | 59 | constructor(el) { |
58 | 60 | this.el = el |
|
91 | 93 | } |
92 | 94 |
|
93 | 95 | evaluateCondition() { |
94 | | - let data_if = this.el.data('if') |
95 | | - let value = data_if ? CONDITIONS[data_if.trim()] : null |
96 | | - if (value) return { condition: value } |
97 | | - |
98 | | - value = this.el.data('eq') |
99 | | - if (value) return { condition: CONDITIONS['eq'], condition_arg: value } |
100 | | - |
101 | | - value = this.el.data('not') |
102 | | - if (value) return { condition: CONDITIONS['not'], condition_arg: value } |
103 | | - |
104 | | - value = this.el.data('match') |
105 | | - if (value) return { condition: CONDITIONS['match'], condition_arg: new RegExp(value) } |
106 | | - |
107 | | - value = this.el.data('mismatch') |
108 | | - if (value) return { condition: CONDITIONS['mismatch'], condition_arg: new RegExp(value) } |
| 96 | + let value |
| 97 | + if (value = this.el.data('if')) { |
| 98 | + if (REGEXP_NOT.test(value)) value = 'not_' + value.replace(REGEXP_NOT, '') |
| 99 | + return { condition: CONDITIONS[value] } |
| 100 | + } |
| 101 | + if (value = this.el.data('eq')) { |
| 102 | + if (REGEXP_NOT.test(value)) { |
| 103 | + return { condition: CONDITIONS['not'], condition_arg: value.replace(REGEXP_NOT, '') } |
| 104 | + } |
| 105 | + return { condition: CONDITIONS['eq'], condition_arg: value } |
| 106 | + } |
| 107 | + if (value = this.el.data('not')) { |
| 108 | + if (REGEXP_NOT.test(value)) { |
| 109 | + return { condition: CONDITIONS['eq'], condition_arg: value.replace(REGEXP_NOT, '') } |
| 110 | + } |
| 111 | + return { condition: CONDITIONS['not'], condition_arg: value } |
| 112 | + } |
| 113 | + if (value = this.el.data('match')) { |
| 114 | + return { condition: CONDITIONS['match'], condition_arg: new RegExp(value) } |
| 115 | + } |
| 116 | + if (value = this.el.data('mismatch')) { |
| 117 | + return { condition: CONDITIONS['mismatch'], condition_arg: new RegExp(value) } |
| 118 | + } |
109 | 119 |
|
110 | 120 | this.custom_function = this.el.data('function') |
111 | 121 | if (this.custom_function) { |
|
0 commit comments