Skip to content

Commit 52bb407

Browse files
committed
Refactor(validation): Update validationType handling with getter/setter and simplify change logic
Signed-off-by: Christian Hartmann <chris-hartmann@gmx.de>
1 parent 9a3f363 commit 52bb407

1 file changed

Lines changed: 20 additions & 27 deletions

File tree

src/components/Questions/QuestionShort.vue

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@
5050
validationTypeObject, validationTypeName
5151
) in validationTypes"
5252
:key="validationTypeName"
53-
:checked="validationType === validationTypeName"
54-
:name="validationTypeName"
55-
@update:checked="onChangeValidationType(validationTypeName)">
53+
v-model="validationType"
54+
:value="validationTypeName"
55+
:name="`${id}_validationMenu`">
5656
{{ validationTypeObject.label }}
5757
</NcActionRadio>
5858
<NcActionInput
@@ -124,8 +124,23 @@ export default {
124124
/**
125125
* Name of the current validation type, fallsback to 'text'
126126
*/
127-
validationType() {
128-
return this.extraSettings?.validationType || 'text'
127+
validationType: {
128+
get() {
129+
return this.extraSettings?.validationType || 'text'
130+
},
131+
set(value) {
132+
if (value === 'regex') {
133+
this.onExtraSettingsChange({
134+
validationType: value,
135+
validationRegex: this.validationRegex,
136+
})
137+
} else {
138+
this.isValidationTypeMenuOpen = false
139+
this.onExtraSettingsChange({
140+
validationType: value === 'text' ? undefined : value,
141+
})
142+
}
143+
},
129144
},
130145
/**
131146
* Id of the validation type menu
@@ -169,28 +184,6 @@ export default {
169184
this.$emit('update:values', [value])
170185
},
171186
172-
/**
173-
* Change input type
174-
*
175-
* @param {string} validationType new input type
176-
*/
177-
onChangeValidationType(validationType) {
178-
if (validationType === 'regex') {
179-
// Make sure to also submit a regex (even if empty)
180-
this.onExtraSettingsChange({
181-
validationType,
182-
validationRegex: this.validationRegex,
183-
})
184-
} else {
185-
// For all other types except regex we close the menu (for regex we keep it open to allow entering a regex)
186-
this.isValidationTypeMenuOpen = false
187-
this.onExtraSettingsChange({
188-
validationType:
189-
validationType === 'text' ? undefined : validationType,
190-
})
191-
}
192-
},
193-
194187
/**
195188
* Validate and save regex if valid
196189
*

0 commit comments

Comments
 (0)