|
86 | 86 | </template> |
87 | 87 |
|
88 | 88 | <script> |
89 | | -/* |
90 | | - Copyright (c) 2020 - present, DITDOT Ltd. - MIT Licence |
91 | | - https://github.com/ditdot-dev/vue-flow-form |
92 | | - https://www.ditdot.hr/en |
93 | | -*/ |
| 89 | + /* |
| 90 | + Copyright (c) 2020 - present, DITDOT Ltd. - MIT Licence |
| 91 | + https://github.com/ditdot-dev/vue-flow-form |
| 92 | + https://www.ditdot.hr/en |
| 93 | + */ |
94 | 94 |
|
95 | | -import BaseType from './BaseType.vue' |
96 | | -import { QuestionType } from '../../models/QuestionModel' |
| 95 | + import BaseType from './BaseType.vue' |
| 96 | + import { QuestionType } from '../../models/QuestionModel' |
97 | 97 |
|
98 | | -export default { |
99 | | - extends: BaseType, |
100 | | - name: QuestionType.Matrix, |
| 98 | + export default { |
| 99 | + extends: BaseType, |
| 100 | + |
| 101 | + name: QuestionType.Matrix, |
101 | 102 |
|
102 | | - data() { |
103 | | - return { |
104 | | - selected: {}, |
105 | | - inputList: [] |
106 | | - } |
107 | | - }, |
| 103 | + data() { |
| 104 | + return { |
| 105 | + selected: {}, |
| 106 | + inputList: [] |
| 107 | + } |
| 108 | + }, |
108 | 109 |
|
109 | | - beforeMount() { |
110 | | - // Pre-fill the form if there is a predefined answer |
111 | | - if (this.question.multiple) { |
112 | | - for (let row of this.question.rows) { |
113 | | - this.selected[row.id] = this.question.answer && this.question.answer[row.id] ? [...this.question.answer[row.id]] : [] |
| 110 | + beforeMount() { |
| 111 | + // Pre-fill the form if there is a predefined answer |
| 112 | + if (this.question.multiple) { |
| 113 | + for (let row of this.question.rows) { |
| 114 | + this.selected[row.id] = this.question.answer && this.question.answer[row.id] ? [...this.question.answer[row.id]] : [] |
| 115 | + } |
| 116 | + } else if (this.question.answer) { |
| 117 | + this.selected = {...this.question.answer} |
114 | 118 | } |
115 | | - } else if (this.question.answer) { |
116 | | - this.selected = {...this.question.answer} |
117 | | - } |
118 | | - }, |
| 119 | + }, |
119 | 120 |
|
120 | | - beforeUpdate() { |
121 | | - this.inputList = [] |
122 | | - }, |
| 121 | + beforeUpdate() { |
| 122 | + this.inputList = [] |
| 123 | + }, |
123 | 124 |
|
124 | | - methods: { |
125 | | - onChange($event) { |
126 | | - this.dirty = true |
127 | | - this.dataValue = this.selected |
128 | | - this.onKeyDown() |
129 | | - this.setAnswer(this.dataValue) |
130 | | - }, |
| 125 | + methods: { |
| 126 | + onChange($event) { |
| 127 | + this.dirty = true |
| 128 | + this.dataValue = this.selected |
| 129 | + this.onKeyDown() |
| 130 | + this.setAnswer(this.dataValue) |
| 131 | + }, |
131 | 132 |
|
132 | | - validate() { |
133 | | - if (!this.question.required) { |
134 | | - return true |
135 | | - } |
| 133 | + validate() { |
| 134 | + if (!this.question.required) { |
| 135 | + return true |
| 136 | + } |
136 | 137 |
|
137 | | - const checked = inputs => inputs.some(input => input.checked) |
| 138 | + const checked = inputs => inputs.some(input => input.checked) |
138 | 139 |
|
139 | | - if (!Object.values(this.inputGroups).every(value => checked(value))) { |
140 | | - return false |
141 | | - } |
| 140 | + if (!Object.values(this.inputGroups).every(value => checked(value))) { |
| 141 | + return false |
| 142 | + } |
| 143 | +
|
| 144 | + return true |
| 145 | + }, |
142 | 146 |
|
143 | | - return true |
| 147 | + getElement() { |
| 148 | + return this.inputList[0] |
| 149 | + }, |
144 | 150 | }, |
145 | 151 |
|
146 | | - getElement() { |
147 | | - return this.inputList[0] |
148 | | - }, |
149 | | - }, |
| 152 | + computed: { |
| 153 | + inputGroups() { |
| 154 | + const inputGroups = {} |
150 | 155 |
|
151 | | - computed: { |
152 | | - inputGroups() { |
153 | | - let inputGroups = {} |
154 | | - // Setting input list for validation |
155 | | - for (let row of this.question.rows) { |
156 | | - inputGroups[row.id] = [] |
157 | | - } |
158 | | - |
159 | | - this.inputList.forEach(input => { |
160 | | - inputGroups[input.dataset.id].push(input) |
161 | | - }) |
| 156 | + // Setting input list for validation |
| 157 | + for (let row of this.question.rows) { |
| 158 | + inputGroups[row.id] = [] |
| 159 | + } |
| 160 | + |
| 161 | + this.inputList.forEach(input => { |
| 162 | + inputGroups[input.dataset.id].push(input) |
| 163 | + }) |
162 | 164 |
|
163 | | - return inputGroups |
| 165 | + return inputGroups |
| 166 | + } |
164 | 167 | } |
165 | 168 | } |
166 | | -} |
167 | 169 | </script> |
0 commit comments