Skip to content

Commit b842d87

Browse files
committed
Add select on number key press to OptionNumberScale
1 parent 5b50c06 commit b842d87

File tree

3 files changed

+53
-16
lines changed

3 files changed

+53
-16
lines changed

src/assets/css/common.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,14 @@ header.vff-header svg.f-logo {
789789
flex: 0 0 calc(10% - 8px);
790790
}
791791

792+
.vff .field-opinionnumberscale ul.f-radios.f-numbers li .f-label-wrap {
793+
justify-content: center;
794+
}
795+
796+
.vff .field-opinionnumberscale ul.f-radios.f-numbers li .f-label {
797+
margin: 0;
798+
}
799+
792800
/*
793801
field matrix
794802
*/

src/components/QuestionTypes/OpinionNumberScaleType.vue

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
88
import OpinionScaleType from './OpinionScaleType.vue'
9-
import { QuestionType } from '../../models/QuestionModel'
9+
import { ChoiceOption, QuestionType } from '../../models/QuestionModel'
1010
1111
export default {
1212
extends: OpinionScaleType,
@@ -16,6 +16,46 @@
1616
return {
1717
isNumberScale: true
1818
}
19-
}
19+
},
20+
21+
beforeMount() {
22+
if (this.question.max && !this.question.options.length) {
23+
const
24+
min = this.question.min || 1,
25+
max = this.question.max
26+
27+
for (let i = min; i <= max; i++) {
28+
this.question.options.push(new ChoiceOption({value: i.toString()}))
29+
}
30+
}
31+
},
32+
33+
methods: {
34+
35+
/**
36+
* Listens for keyboard events (1, 2, 3, ...)
37+
*/
38+
onKeyListener($event) {
39+
if (this.active && $event.key && $event.key.length === 1) {
40+
let keyCode = $event.key.toUpperCase().charCodeAt(0)
41+
console.log(keyCode)
42+
if (keyCode >= 48 && keyCode <= 57) {
43+
let index = keyCode - 49
44+
45+
if (index > -1) {
46+
let option = this.question.options[index]
47+
48+
if (option) {
49+
this.toggleAnswer(option)
50+
}
51+
}
52+
}
53+
}
54+
},
55+
56+
getToggleKey(num) {
57+
return num
58+
},
59+
},
2060
}
2161
</script>

src/components/QuestionTypes/OpinionScaleType.vue

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div class="f-radios-wrap">
3-
<ul class="f-radios" v-bind:class="{'f-numbers': question.max}" role="listbox">
3+
<ul class="f-radios" v-bind:class="{'f-numbers': isNumberScale}" role="listbox">
44
<li
55
v-for="(option, index) in question.options"
66
v-on:click.prevent="toggleAnswer(option)"
@@ -10,7 +10,7 @@
1010
role="option"
1111
>
1212
<div class="f-label-wrap">
13-
<span class="f-key">{{ getToggleKey(index) }}</span>
13+
<span v-if="!isNumberScale" class="f-key">{{ getToggleKey(index) }}</span>
1414
<span v-if="option.choiceLabel()" class="f-label">{{ option.choiceLabel() }}</span>
1515
</div>
1616
</li>
@@ -38,17 +38,6 @@
3838
}
3939
},
4040
41-
beforeMount() {
42-
if (this.question.max && !this.question.options.length) {
43-
const
44-
min = this.question.min || 1,
45-
max = this.question.max
46-
for (let i = min; i <= max; i++) {
47-
this.question.options.push(new ChoiceOption({value: i.toString()}))
48-
}
49-
}
50-
},
51-
5241
mounted() {
5342
this.addKeyListener()
5443
},
@@ -103,6 +92,7 @@
10392
},
10493
10594
getToggleKey(index) {
95+
console.log(index)
10696
const key = 65 + index
10797
10898
if (key <= 90) {
@@ -126,7 +116,6 @@
126116
127117
_toggleAnswer(option) {
128118
const optionValue = option.choiceValue()
129-
console.log(option, optionValue)
130119
131120
option.toggle()
132121

0 commit comments

Comments
 (0)