Skip to content

Commit baec31d

Browse files
committed
Fix questions as components with Vue3
1 parent 6abc79c commit baec31d

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

src/components/FlowForm.vue

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -295,36 +295,39 @@
295295
296296
if (!this.questions) {
297297
const classMap = {
298-
'options': ChoiceOption,
299-
'descriptionLink': LinkOption
298+
options: ChoiceOption,
299+
descriptionLink: LinkOption
300300
}
301301
302+
window.a = this
303+
302304
this
303305
.$slots
304-
.default
305-
.filter(q => q.tag && q.tag.indexOf('Question') !== -1)
306+
.default()[0]
307+
.children
308+
.filter(q => q.type && q.type.name.indexOf('Question') !== -1)
306309
.forEach(q => {
307-
const attrs = q.data.attrs
310+
const props = q.props
308311
let model = new QuestionModel()
309312
310-
if (q.componentInstance.question !== null) {
311-
model = q.componentInstance.question
313+
if (q.question !== undefined) {
314+
model = q.question
312315
}
313316
314-
if (q.data.model) {
315-
model.answer = q.data.model.value
317+
if (props.modelValue) {
318+
model.answer = props.modelValue
316319
}
317320
318321
Object.keys(model).forEach(key => {
319-
if (attrs[key] !== undefined) {
322+
if (props[key] !== undefined) {
320323
if (typeof model[key] === 'boolean') {
321-
model[key] = attrs[key] !== false
324+
model[key] = props[key] !== false
322325
} else if (key in classMap) {
323326
const
324327
classReference = classMap[key],
325328
options = []
326329
327-
attrs[key].forEach(option => {
330+
props[key].forEach(option => {
328331
const instance = new classReference()
329332
330333
Object.keys(instance).forEach(instanceKey => {
@@ -340,11 +343,11 @@
340343
} else {
341344
switch(key) {
342345
case 'type':
343-
if (Object.values(QuestionType).indexOf(attrs[key]) !== -1) {
344-
model[key] = attrs[key]
346+
if (Object.values(QuestionType).indexOf(props[key]) !== -1) {
347+
model[key] = props[key]
345348
} else {
346349
for (const questionTypeKey in QuestionType) {
347-
if (questionTypeKey.toLowerCase() === attrs[key].toLowerCase()) {
350+
if (questionTypeKey.toLowerCase() === props[key].toLowerCase()) {
348351
model[key] = QuestionType[questionTypeKey]
349352
break
350353
}
@@ -353,14 +356,14 @@
353356
break
354357
355358
default:
356-
model[key] = attrs[key]
359+
model[key] = props[key]
357360
break
358361
}
359362
}
360363
}
361364
})
362365
363-
q.componentInstance.question = model
366+
q.question = model
364367
365368
model.resetOptions()
366369

0 commit comments

Comments
 (0)