Skip to content

Commit 16ebe33

Browse files
authored
fix: Add validation and consistent data structure for survey 'Other' options (#5620)
## Summary - Added validation to prevent users from proceeding when "Other" is selected but text input is empty - Changed data structure to send consistent string values to database instead of mixed objects - Both useCase and industry now send user input directly when "Other" is selected ## Changes - Added `useCaseOther` field and input to survey form - Updated `validStep2` to validate useCaseOther when useCase is 'other' - Modified submit payload to send string values consistently for both useCase and industry fields ## Test plan - [x] Select "Other" for use case without filling input → Next button disabled - [x] Select "Other" for industry without filling input → Next button disabled - [x] Fill in "Other" text inputs → Next button enabled - [x] Submit survey with "Other" selections → Payload sends user input as string values 🤖 Generated with [Claude Code](https://claude.ai/code) ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-5620-fix-Add-validation-and-consistent-data-structure-for-survey-Other-options-2716d73d3650811faa6efc547db14930) by [Unito](https://www.unito.io)
1 parent 108ad22 commit 16ebe33

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

src/platform/onboarding/cloud/CloudSurveyView.vue

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@
8080
>
8181
</div>
8282
</div>
83+
<div v-if="surveyData.useCase === 'other'" class="mt-4 ml-8">
84+
<InputText
85+
v-model="surveyData.useCaseOther"
86+
class="w-full"
87+
placeholder="Please specify"
88+
/>
89+
</div>
8390
</div>
8491

8592
<div class="flex gap-6 pt-4">
@@ -243,6 +250,7 @@ const isSubmitting = ref(false)
243250
const surveyData = ref({
244251
familiarity: '',
245252
useCase: '',
253+
useCaseOther: '',
246254
industry: '',
247255
industryOther: '',
248256
making: [] as string[]
@@ -265,7 +273,8 @@ const purposeOptions = [
265273
},
266274
{ label: 'Client work (freelance)', value: 'client' },
267275
{ label: 'My own workplace (in-house)', value: 'inhouse' },
268-
{ label: 'Academic research', value: 'research' }
276+
{ label: 'Academic research', value: 'research' },
277+
{ label: 'Other', value: 'other' }
269278
]
270279
271280
const industryOptions = [
@@ -290,7 +299,13 @@ const makingOptions = [
290299
291300
// Validation per step
292301
const validStep1 = computed(() => !!surveyData.value.familiarity)
293-
const validStep2 = computed(() => !!surveyData.value.useCase)
302+
const validStep2 = computed(() => {
303+
if (!surveyData.value.useCase) return false
304+
if (surveyData.value.useCase === 'other') {
305+
return !!surveyData.value.useCaseOther?.trim()
306+
}
307+
return true
308+
})
294309
const validStep3 = computed(() => {
295310
if (!surveyData.value.industry) return false
296311
if (surveyData.value.industry === 'other') {
@@ -314,13 +329,16 @@ const goTo = (step: number, activate: (val: string | number) => void) => {
314329
const onSubmitSurvey = async () => {
315330
try {
316331
isSubmitting.value = true
317-
// prepare payload: collapse "other" field
332+
// prepare payload with consistent structure
318333
const payload = {
319334
familiarity: surveyData.value.familiarity,
320-
useCase: surveyData.value.useCase,
335+
useCase:
336+
surveyData.value.useCase === 'other'
337+
? surveyData.value.useCaseOther?.trim() || 'other'
338+
: surveyData.value.useCase,
321339
industry:
322340
surveyData.value.industry === 'other'
323-
? { type: 'other', text: surveyData.value.industryOther }
341+
? surveyData.value.industryOther?.trim() || 'other'
324342
: surveyData.value.industry,
325343
making: surveyData.value.making
326344
}

0 commit comments

Comments
 (0)