@eturnity/eturnity_reusable_components 1.0.39 → 1.0.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
package/src/App.vue
CHANGED
|
@@ -13,7 +13,20 @@
|
|
|
13
13
|
</thead>
|
|
14
14
|
<tbody>
|
|
15
15
|
<tr>
|
|
16
|
-
<td
|
|
16
|
+
<td>
|
|
17
|
+
<input-number
|
|
18
|
+
placeholder="Enter distance"
|
|
19
|
+
:isError="false"
|
|
20
|
+
:numberPrecision="2"
|
|
21
|
+
unitName="pc"
|
|
22
|
+
:value="inputValue"
|
|
23
|
+
@input-change="onInputChange($event)"
|
|
24
|
+
errorMessage="Enter a number between 1 and 10"
|
|
25
|
+
:disabled="false"
|
|
26
|
+
:noBorder="true"
|
|
27
|
+
textAlign="left"
|
|
28
|
+
/>
|
|
29
|
+
</td>
|
|
17
30
|
<td class="text">Body 2</td>
|
|
18
31
|
<td class="text">Body 3</td>
|
|
19
32
|
<td class="text">Body 4</td>
|
|
@@ -23,17 +36,6 @@
|
|
|
23
36
|
</tr>
|
|
24
37
|
</tbody>
|
|
25
38
|
</main-table>
|
|
26
|
-
<toggle
|
|
27
|
-
@on-toggle-change="onInputChange($event)"
|
|
28
|
-
:isChecked="inputValue"
|
|
29
|
-
size="medium"
|
|
30
|
-
:disabled="true"
|
|
31
|
-
/>
|
|
32
|
-
<toggle
|
|
33
|
-
@on-toggle-change="onInputChange($event)"
|
|
34
|
-
:isChecked="inputValue"
|
|
35
|
-
size="small"
|
|
36
|
-
/>
|
|
37
39
|
</page-container>
|
|
38
40
|
</ThemeProvider>
|
|
39
41
|
</template>
|
|
@@ -44,7 +46,7 @@ import theme from "./assets/theme"
|
|
|
44
46
|
import styled from "vue-styled-components"
|
|
45
47
|
import MainTable from "@/components/tables/mainTable"
|
|
46
48
|
import ThreeDots from "@/components/threeDots"
|
|
47
|
-
import
|
|
49
|
+
import InputNumber from "@/components/inputs/inputNumber"
|
|
48
50
|
|
|
49
51
|
const PageContainer = styled.div`
|
|
50
52
|
padding: 40px;
|
|
@@ -57,11 +59,11 @@ export default {
|
|
|
57
59
|
PageContainer,
|
|
58
60
|
MainTable,
|
|
59
61
|
ThreeDots,
|
|
60
|
-
|
|
62
|
+
InputNumber,
|
|
61
63
|
},
|
|
62
64
|
data() {
|
|
63
65
|
return {
|
|
64
|
-
inputValue:
|
|
66
|
+
inputValue: "",
|
|
65
67
|
checkedOption: "button_1",
|
|
66
68
|
question: {
|
|
67
69
|
number_format_precision: 4,
|
|
@@ -2,21 +2,24 @@
|
|
|
2
2
|
<container>
|
|
3
3
|
<input-wrapper>
|
|
4
4
|
<input-container
|
|
5
|
-
:hasUnit="!!
|
|
5
|
+
:hasUnit="unitName && !!unitName.length"
|
|
6
6
|
:placeholder="placeholder"
|
|
7
7
|
:isError="isError"
|
|
8
8
|
:inputWidth="inputWidth"
|
|
9
|
-
:value="
|
|
10
|
-
:hasLength="!!
|
|
11
|
-
@
|
|
12
|
-
@
|
|
9
|
+
:value="formatWithCurrency(value)"
|
|
10
|
+
:hasLength="!!value.length"
|
|
11
|
+
@blur="onInputBlur($event)"
|
|
12
|
+
@focus="focusInput()"
|
|
13
13
|
@keyup.enter="$emit('on-enter-click')"
|
|
14
|
+
:disabled="disabled"
|
|
15
|
+
:noBorder="noBorder"
|
|
16
|
+
:textAlign="textAlign"
|
|
14
17
|
/>
|
|
15
18
|
<unit-container
|
|
16
|
-
v-if="
|
|
19
|
+
v-if="unitName && showLinearUnitName"
|
|
17
20
|
:hasLength="!!textInput.length"
|
|
18
21
|
:isError="isError"
|
|
19
|
-
>{{
|
|
22
|
+
>{{ unitName }}</unit-container
|
|
20
23
|
>
|
|
21
24
|
</input-wrapper>
|
|
22
25
|
<error-message v-if="isError">{{ errorMessage }}</error-message>
|
|
@@ -24,26 +27,24 @@
|
|
|
24
27
|
</template>
|
|
25
28
|
|
|
26
29
|
<script>
|
|
27
|
-
// import
|
|
30
|
+
// import InputNumberQuestion from "@eturnity/eturnity_reusable_components/src/components/inputs/inputNumberQuestion"
|
|
28
31
|
//This component should be used for questions with input fields only
|
|
29
32
|
//How to use:
|
|
30
33
|
// <input-number
|
|
31
34
|
// placeholder="Enter distance"
|
|
32
35
|
// :isError="false" //default is false
|
|
33
36
|
// inputWidth="150px" //by default, this is 100%
|
|
34
|
-
// :
|
|
37
|
+
// :numberPrecision="3"
|
|
38
|
+
// unitName="pc"
|
|
35
39
|
// :value="inputValue" //required -- String
|
|
36
40
|
// @input-change="onInputChange($event)" //required
|
|
37
41
|
// @on-enter-click="onInputSubmit()"
|
|
38
42
|
// :errorMessage="Enter a number between 1 and 10"
|
|
43
|
+
// :disabled="false"
|
|
44
|
+
// :noBorder="true"
|
|
45
|
+
// textAlign="left" // "left, right, center"
|
|
46
|
+
// :showLinearUnitName="true"
|
|
39
47
|
// />
|
|
40
|
-
// question data example:
|
|
41
|
-
// question: {
|
|
42
|
-
// number_format_precision: 4,
|
|
43
|
-
// number_min_allowed: 0,
|
|
44
|
-
// number_max_allowed: 10,
|
|
45
|
-
// unit_short_name: "cm",
|
|
46
|
-
// },
|
|
47
48
|
import styled from "vue-styled-components"
|
|
48
49
|
import {
|
|
49
50
|
stringToNumber,
|
|
@@ -60,22 +61,32 @@ const inputProps = {
|
|
|
60
61
|
hasUnit: Boolean,
|
|
61
62
|
inputWidth: String,
|
|
62
63
|
hasLength: Boolean,
|
|
64
|
+
disabled: Boolean,
|
|
65
|
+
noBorder: Boolean,
|
|
66
|
+
textAlign: String,
|
|
63
67
|
}
|
|
64
68
|
const InputContainer = styled("input", inputProps)`
|
|
65
|
-
border:
|
|
66
|
-
|
|
67
|
-
props.
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
border: ${(props) =>
|
|
70
|
+
props.isError
|
|
71
|
+
? "1px solid " + props.theme.colors.red
|
|
72
|
+
: props.noBorder
|
|
73
|
+
? "none"
|
|
74
|
+
: props.hasLength
|
|
75
|
+
? "1px solid " + props.theme.colors.black
|
|
76
|
+
: "1px solid " + props.theme.colors.mediumGray};
|
|
72
77
|
padding: ${(props) =>
|
|
73
78
|
props.hasUnit ? "11px 40px 11px 10px" : "11px 5px 11px 10px"};
|
|
74
79
|
border-radius: 4px;
|
|
80
|
+
text-align: ${(props) => props.textAlign};
|
|
81
|
+
cursor: ${(props) => (props.disabled ? "not-allowed" : "auto")};
|
|
75
82
|
font-size: 16px;
|
|
76
83
|
color: ${(props) =>
|
|
77
|
-
props.isError ? props.theme.colors.red : props.theme.colors.
|
|
78
|
-
width: ${(props) => (props.inputWidth ? props.inputWidth : "
|
|
84
|
+
props.isError ? props.theme.colors.red : props.theme.colors.black};
|
|
85
|
+
width: ${(props) => (props.inputWidth ? props.inputWidth : "100%")};
|
|
86
|
+
background-color: ${(props) =>
|
|
87
|
+
props.disabled
|
|
88
|
+
? props.theme.colors.grey5 + " !important"
|
|
89
|
+
: "#fff !important"};
|
|
79
90
|
|
|
80
91
|
&::placeholder {
|
|
81
92
|
color: ${(props) =>
|
|
@@ -97,7 +108,7 @@ const UnitContainer = styled("span", inputProps)`
|
|
|
97
108
|
props.isError
|
|
98
109
|
? props.theme.colors.red
|
|
99
110
|
: props.hasLength
|
|
100
|
-
? props.theme.colors.
|
|
111
|
+
? props.theme.colors.black
|
|
101
112
|
: props.theme.colors.mediumGray};
|
|
102
113
|
position: absolute;
|
|
103
114
|
right: 10px;
|
|
@@ -107,7 +118,7 @@ const UnitContainer = styled("span", inputProps)`
|
|
|
107
118
|
props.isError
|
|
108
119
|
? props.theme.colors.red
|
|
109
120
|
: props.hasLength
|
|
110
|
-
? props.theme.colors.
|
|
121
|
+
? props.theme.colors.black
|
|
111
122
|
: props.theme.colors.mediumGray};
|
|
112
123
|
`
|
|
113
124
|
|
|
@@ -129,9 +140,7 @@ export default {
|
|
|
129
140
|
data() {
|
|
130
141
|
return {
|
|
131
142
|
textInput: "",
|
|
132
|
-
|
|
133
|
-
minValue: 0,
|
|
134
|
-
maxValue: 100,
|
|
143
|
+
isFocused: false,
|
|
135
144
|
}
|
|
136
145
|
},
|
|
137
146
|
props: {
|
|
@@ -143,9 +152,6 @@ export default {
|
|
|
143
152
|
required: false,
|
|
144
153
|
default: false,
|
|
145
154
|
},
|
|
146
|
-
question: {
|
|
147
|
-
required: true,
|
|
148
|
-
},
|
|
149
155
|
inputWidth: {
|
|
150
156
|
required: false,
|
|
151
157
|
default: null,
|
|
@@ -162,35 +168,97 @@ export default {
|
|
|
162
168
|
required: false,
|
|
163
169
|
default: "Please insert a correct number",
|
|
164
170
|
},
|
|
171
|
+
numberPrecision: {
|
|
172
|
+
required: false,
|
|
173
|
+
default: 0,
|
|
174
|
+
},
|
|
175
|
+
unitName: {
|
|
176
|
+
required: false,
|
|
177
|
+
default: "",
|
|
178
|
+
},
|
|
179
|
+
showLinearUnitName: {
|
|
180
|
+
required: false,
|
|
181
|
+
default: false,
|
|
182
|
+
},
|
|
183
|
+
disabled: {
|
|
184
|
+
required: false,
|
|
185
|
+
default: false,
|
|
186
|
+
},
|
|
187
|
+
noBorder: {
|
|
188
|
+
required: false,
|
|
189
|
+
default: false,
|
|
190
|
+
},
|
|
191
|
+
textAlign: {
|
|
192
|
+
required: false,
|
|
193
|
+
default: "left",
|
|
194
|
+
},
|
|
165
195
|
},
|
|
166
196
|
methods: {
|
|
167
|
-
onChangeHandler(
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
value: $event,
|
|
171
|
-
numberPrecision: this.numberPrecision,
|
|
172
|
-
})
|
|
173
|
-
if (isNaN(formattedValue)) {
|
|
174
|
-
this.textInput = ""
|
|
175
|
-
formattedValue = ""
|
|
197
|
+
onChangeHandler(event) {
|
|
198
|
+
if (isNaN(event)) {
|
|
199
|
+
event = ""
|
|
176
200
|
}
|
|
177
|
-
this.$emit("input-change",
|
|
201
|
+
this.$emit("input-change", event)
|
|
178
202
|
},
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
203
|
+
onEvaluateCode(val) {
|
|
204
|
+
// function to perform math on the code
|
|
205
|
+
// filter the string in case of any malicious content
|
|
206
|
+
let filtered = val.replace(/[^-()\d/*+.,]/g, "")
|
|
207
|
+
filtered = filtered.split(/([-+*/()])/)
|
|
208
|
+
let formatted = filtered.map((item) => {
|
|
209
|
+
if (
|
|
210
|
+
item === "+" ||
|
|
211
|
+
item === "-" ||
|
|
212
|
+
item === "*" ||
|
|
213
|
+
item === "/" ||
|
|
214
|
+
item === "(" ||
|
|
215
|
+
item === ")" ||
|
|
216
|
+
item === ""
|
|
217
|
+
) {
|
|
218
|
+
return item
|
|
219
|
+
} else {
|
|
220
|
+
let num = stringToNumber({
|
|
221
|
+
value: item,
|
|
222
|
+
numberPrecision: this.numberPrecision,
|
|
223
|
+
})
|
|
224
|
+
return num
|
|
225
|
+
}
|
|
187
226
|
})
|
|
227
|
+
let evaluated = eval(formatted.join(""))
|
|
228
|
+
return evaluated
|
|
229
|
+
},
|
|
230
|
+
onInputBlur(e) {
|
|
231
|
+
this.isFocused = false
|
|
232
|
+
let value = e.target.value
|
|
233
|
+
let evaluatedInput = this.onEvaluateCode(value)
|
|
234
|
+
this.onChangeHandler(evaluatedInput)
|
|
235
|
+
if (value.length) {
|
|
236
|
+
this.textInput = numberToString({
|
|
237
|
+
value: evaluatedInput,
|
|
238
|
+
numberPrecision: this.numberPrecision,
|
|
239
|
+
})
|
|
240
|
+
}
|
|
241
|
+
},
|
|
242
|
+
focusInput() {
|
|
243
|
+
this.isFocused = true
|
|
244
|
+
},
|
|
245
|
+
formatWithCurrency(value) {
|
|
246
|
+
if (value && !this.isFocused) {
|
|
247
|
+
let input = numberToString({
|
|
248
|
+
value: value,
|
|
249
|
+
numberPrecision: this.numberPrecision,
|
|
250
|
+
})
|
|
251
|
+
let unit = this.showLinearUnitName ? "" : this.unitName
|
|
252
|
+
return input + " " + unit
|
|
253
|
+
} else {
|
|
254
|
+
return numberToString({
|
|
255
|
+
value: value,
|
|
256
|
+
numberPrecision: this.numberPrecision,
|
|
257
|
+
})
|
|
258
|
+
}
|
|
188
259
|
},
|
|
189
260
|
},
|
|
190
261
|
created() {
|
|
191
|
-
this.numberPrecision = this.question.number_format_precision
|
|
192
|
-
this.minValue = this.question.number_min_allowed
|
|
193
|
-
this.maxValue = this.question.number_max_allowed
|
|
194
262
|
if (this.value) {
|
|
195
263
|
this.textInput = numberToString({
|
|
196
264
|
value: this.value,
|
|
@@ -205,11 +273,6 @@ export default {
|
|
|
205
273
|
this.textInput = ""
|
|
206
274
|
}
|
|
207
275
|
},
|
|
208
|
-
question: function (value) {
|
|
209
|
-
this.numberPrecision = value.number_format_precision
|
|
210
|
-
this.minValue = value.number_min_allowed
|
|
211
|
-
this.maxValue = value.number_max_allowed
|
|
212
|
-
},
|
|
213
276
|
},
|
|
214
277
|
}
|
|
215
278
|
</script>
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<container>
|
|
3
|
+
<input-wrapper>
|
|
4
|
+
<input-container
|
|
5
|
+
:hasUnit="!!question.unit_short_name"
|
|
6
|
+
:placeholder="placeholder"
|
|
7
|
+
:isError="isError"
|
|
8
|
+
:inputWidth="inputWidth"
|
|
9
|
+
:value="textInput"
|
|
10
|
+
:hasLength="!!textInput.length"
|
|
11
|
+
@input="onChangeHandler"
|
|
12
|
+
@blur="onInputBlur()"
|
|
13
|
+
@keyup.enter="$emit('on-enter-click')"
|
|
14
|
+
/>
|
|
15
|
+
<unit-container
|
|
16
|
+
v-if="question.unit_short_name"
|
|
17
|
+
:hasLength="!!textInput.length"
|
|
18
|
+
:isError="isError"
|
|
19
|
+
>{{ question.unit_short_name }}</unit-container
|
|
20
|
+
>
|
|
21
|
+
</input-wrapper>
|
|
22
|
+
<error-message v-if="isError">{{ errorMessage }}</error-message>
|
|
23
|
+
</container>
|
|
24
|
+
</template>
|
|
25
|
+
|
|
26
|
+
<script>
|
|
27
|
+
// import InputNumberQuestion from "@eturnity/eturnity_reusable_components/src/components/inputs/inputNumberQuestion"
|
|
28
|
+
//This component should be used for questions with input fields only
|
|
29
|
+
//How to use:
|
|
30
|
+
// <input-number
|
|
31
|
+
// placeholder="Enter distance"
|
|
32
|
+
// :isError="false" //default is false
|
|
33
|
+
// inputWidth="150px" //by default, this is 100%
|
|
34
|
+
// :question="question"
|
|
35
|
+
// :value="inputValue" //required -- String
|
|
36
|
+
// @input-change="onInputChange($event)" //required
|
|
37
|
+
// @on-enter-click="onInputSubmit()"
|
|
38
|
+
// :errorMessage="Enter a number between 1 and 10"
|
|
39
|
+
// />
|
|
40
|
+
// question data example:
|
|
41
|
+
// question: {
|
|
42
|
+
// number_format_precision: 4,
|
|
43
|
+
// number_min_allowed: 0,
|
|
44
|
+
// number_max_allowed: 10,
|
|
45
|
+
// unit_short_name: "cm",
|
|
46
|
+
// },
|
|
47
|
+
import styled from "vue-styled-components"
|
|
48
|
+
import {
|
|
49
|
+
stringToNumber,
|
|
50
|
+
numberToString,
|
|
51
|
+
} from "../../../helpers/numberConverter"
|
|
52
|
+
|
|
53
|
+
const Container = styled.div`
|
|
54
|
+
width: 100%;
|
|
55
|
+
position: relative;
|
|
56
|
+
`
|
|
57
|
+
|
|
58
|
+
const inputProps = {
|
|
59
|
+
isError: Boolean,
|
|
60
|
+
hasUnit: Boolean,
|
|
61
|
+
inputWidth: String,
|
|
62
|
+
hasLength: Boolean,
|
|
63
|
+
}
|
|
64
|
+
const InputContainer = styled("input", inputProps)`
|
|
65
|
+
border: 1px solid
|
|
66
|
+
${(props) =>
|
|
67
|
+
props.isError
|
|
68
|
+
? props.theme.colors.red
|
|
69
|
+
: props.hasLength
|
|
70
|
+
? props.theme.colors.primary
|
|
71
|
+
: props.theme.colors.mediumGray};
|
|
72
|
+
padding: ${(props) =>
|
|
73
|
+
props.hasUnit ? "11px 40px 11px 10px" : "11px 5px 11px 10px"};
|
|
74
|
+
border-radius: 4px;
|
|
75
|
+
font-size: 16px;
|
|
76
|
+
color: ${(props) =>
|
|
77
|
+
props.isError ? props.theme.colors.red : props.theme.colors.primary};
|
|
78
|
+
width: ${(props) => (props.inputWidth ? props.inputWidth : "auto")};
|
|
79
|
+
|
|
80
|
+
&::placeholder {
|
|
81
|
+
color: ${(props) =>
|
|
82
|
+
props.isError ? props.theme.colors.red : props.theme.colors.darkGray};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
&:focus {
|
|
86
|
+
outline: none;
|
|
87
|
+
}
|
|
88
|
+
`
|
|
89
|
+
|
|
90
|
+
const InputWrapper = styled.span`
|
|
91
|
+
position: relative;
|
|
92
|
+
`
|
|
93
|
+
|
|
94
|
+
const UnitContainer = styled("span", inputProps)`
|
|
95
|
+
border-left: 1px solid
|
|
96
|
+
${(props) =>
|
|
97
|
+
props.isError
|
|
98
|
+
? props.theme.colors.red
|
|
99
|
+
: props.hasLength
|
|
100
|
+
? props.theme.colors.primary
|
|
101
|
+
: props.theme.colors.mediumGray};
|
|
102
|
+
position: absolute;
|
|
103
|
+
right: 10px;
|
|
104
|
+
top: 0;
|
|
105
|
+
padding-left: 10px;
|
|
106
|
+
color: ${(props) =>
|
|
107
|
+
props.isError
|
|
108
|
+
? props.theme.colors.red
|
|
109
|
+
: props.hasLength
|
|
110
|
+
? props.theme.colors.primary
|
|
111
|
+
: props.theme.colors.mediumGray};
|
|
112
|
+
`
|
|
113
|
+
|
|
114
|
+
const ErrorMessage = styled.div`
|
|
115
|
+
font-size: 14px;
|
|
116
|
+
color: ${(props) => props.theme.colors.red};
|
|
117
|
+
padding-top: 16px;
|
|
118
|
+
`
|
|
119
|
+
|
|
120
|
+
export default {
|
|
121
|
+
name: "input-number-question",
|
|
122
|
+
components: {
|
|
123
|
+
Container,
|
|
124
|
+
InputContainer,
|
|
125
|
+
InputWrapper,
|
|
126
|
+
UnitContainer,
|
|
127
|
+
ErrorMessage,
|
|
128
|
+
},
|
|
129
|
+
data() {
|
|
130
|
+
return {
|
|
131
|
+
textInput: "",
|
|
132
|
+
numberPrecision: 0, // we set this on created. By default is 0
|
|
133
|
+
minValue: 0,
|
|
134
|
+
maxValue: 100,
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
props: {
|
|
138
|
+
placeholder: {
|
|
139
|
+
required: false,
|
|
140
|
+
default: "",
|
|
141
|
+
},
|
|
142
|
+
isError: {
|
|
143
|
+
required: false,
|
|
144
|
+
default: false,
|
|
145
|
+
},
|
|
146
|
+
question: {
|
|
147
|
+
required: true,
|
|
148
|
+
},
|
|
149
|
+
inputWidth: {
|
|
150
|
+
required: false,
|
|
151
|
+
default: null,
|
|
152
|
+
},
|
|
153
|
+
value: {
|
|
154
|
+
required: true,
|
|
155
|
+
default: null,
|
|
156
|
+
},
|
|
157
|
+
clearInput: {
|
|
158
|
+
required: false,
|
|
159
|
+
default: false,
|
|
160
|
+
},
|
|
161
|
+
errorMessage: {
|
|
162
|
+
required: false,
|
|
163
|
+
default: "Please insert a correct number",
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
methods: {
|
|
167
|
+
onChangeHandler($event) {
|
|
168
|
+
this.textInput = $event
|
|
169
|
+
let formattedValue = stringToNumber({
|
|
170
|
+
value: $event,
|
|
171
|
+
numberPrecision: this.numberPrecision,
|
|
172
|
+
})
|
|
173
|
+
if (isNaN(formattedValue)) {
|
|
174
|
+
this.textInput = ""
|
|
175
|
+
formattedValue = ""
|
|
176
|
+
}
|
|
177
|
+
this.$emit("input-change", formattedValue)
|
|
178
|
+
},
|
|
179
|
+
onInputBlur() {
|
|
180
|
+
let num = stringToNumber({
|
|
181
|
+
value: this.textInput,
|
|
182
|
+
numberPrecision: this.numberPrecision,
|
|
183
|
+
})
|
|
184
|
+
this.textInput = numberToString({
|
|
185
|
+
value: num,
|
|
186
|
+
numberPrecision: this.numberPrecision,
|
|
187
|
+
})
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
created() {
|
|
191
|
+
this.numberPrecision = this.question.number_format_precision
|
|
192
|
+
this.minValue = this.question.number_min_allowed
|
|
193
|
+
this.maxValue = this.question.number_max_allowed
|
|
194
|
+
if (this.value) {
|
|
195
|
+
this.textInput = numberToString({
|
|
196
|
+
value: this.value,
|
|
197
|
+
numberPrecision: this.numberPrecision,
|
|
198
|
+
})
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
watch: {
|
|
202
|
+
clearInput: function (value) {
|
|
203
|
+
if (value) {
|
|
204
|
+
// If the value is typed, then we should clear the textInput on Continue
|
|
205
|
+
this.textInput = ""
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
question: function (value) {
|
|
209
|
+
this.numberPrecision = value.number_format_precision
|
|
210
|
+
this.minValue = value.number_min_allowed
|
|
211
|
+
this.maxValue = value.number_max_allowed
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
}
|
|
215
|
+
</script>
|
|
@@ -7,24 +7,24 @@ export const stringToNumber = ({ value, numberPrecision }) => {
|
|
|
7
7
|
// replace commas with a dot, and dots with blank
|
|
8
8
|
newVal = newVal
|
|
9
9
|
.replace(/[^\d.,']/g, "")
|
|
10
|
-
.replace(/[.\s]
|
|
10
|
+
.replace(/[.\s]/g, "")
|
|
11
11
|
.replace(/[,\s]/, ".")
|
|
12
12
|
} else if (selectedLang === "en-us") {
|
|
13
13
|
// replace commas with blank
|
|
14
|
-
newVal = newVal.replace(/[^\d.,']/g, "").replace(/[,\s]
|
|
14
|
+
newVal = newVal.replace(/[^\d.,']/g, "").replace(/[,\s]/g, "")
|
|
15
15
|
} else if (
|
|
16
16
|
selectedLang === "de-ch" ||
|
|
17
17
|
selectedLang === "fr-ch" ||
|
|
18
18
|
selectedLang === "it-ch"
|
|
19
19
|
) {
|
|
20
20
|
// replace ' with blank
|
|
21
|
-
newVal = newVal.replace(/[^\d.,']/g, "").replace(/['\s]
|
|
21
|
+
newVal = newVal.replace(/[^\d.,']/g, "").replace(/['\s]/g, "")
|
|
22
22
|
} else if (selectedLang === "fr-fr") {
|
|
23
23
|
// replace space with blank, and commas with dot
|
|
24
|
-
newVal = newVal.replace(/[^\d.,']/g, "").replace(/[,\s]
|
|
24
|
+
newVal = newVal.replace(/[^\d.,']/g, "").replace(/[,\s]/g, ".")
|
|
25
25
|
} else {
|
|
26
26
|
// en-US as default
|
|
27
|
-
newVal = newVal.replace(/[^\d.,']/g, "").replace(/[,\s]
|
|
27
|
+
newVal = newVal.replace(/[^\d.,']/g, "").replace(/[,\s]/g, "")
|
|
28
28
|
}
|
|
29
29
|
newVal = parseFloat(newVal).toFixed(numberPrecision)
|
|
30
30
|
return parseFloat(newVal)
|