Files
docuseal/app/javascript/submission_form/form.vue
T

1791 lines
57 KiB
Vue
Raw Normal View History

2023-05-25 22:47:52 +03:00
<template>
2026-04-17 14:49:14 +03:00
<Teleport
v-if="withAccessibilityAreas === null && !isAccessibilityMode"
to="#sr_only_content"
>
<button
class="sr-only focus:not-sr-only focus:absolute focus:top-2 focus:left-2 focus:z-[100] focus:px-4 focus:py-2 focus:bg-base-100 focus:text-base-content focus:rounded focus:shadow-lg"
@click="isAccessibilityMode = true"
>
{{ t('enter_screen_reader_mode') }}
</button>
</Teleport>
<Teleport
v-for="item in (withAccessibilityAreas === null ? schema : [])"
:key="item.attachment_uuid"
:to="`#document-${item.attachment_uuid} .sr_only_content`"
>
<button
v-if="!isAccessibilityMode"
class="sr-only focus:not-sr-only focus:absolute focus:top-2 focus:left-2 focus:z-[100] focus:px-4 focus:py-2 focus:bg-base-100 focus:text-base-content focus:rounded focus:shadow-lg"
@click="isAccessibilityMode = true"
>
{{ t('enter_screen_reader_mode') }}
</button>
</Teleport>
<AccessibilityAreas
v-if="withAccessibilityAreas || isAccessibilityMode"
ref="areas"
:submitter-slug="submitterSlug"
:steps="stepFields"
:readonly-conditional-fields="readonlyConditionalFields"
:readonly-conditional-field-values="readonlyConditionalFieldValues"
:formula-fields="formulaFields"
:values="values"
:readonly-values="readonlyFieldValues"
:submitter="submitter"
:scroll-el="scrollEl"
:current-step="currentStepFields"
:with-field-placeholder="withFieldPlaceholder"
:with-signature-id="withSignatureId"
:with-label="withFieldLabels && !isAnonymousChecboxes && showFieldNames"
:scroll-padding="scrollPadding"
:attachments-index="attachmentsIndex"
:fetch-options="fetchOptions"
:filled-fields-index="filledFieldsIndex"
@focus-step="[saveStep(), currentField.type !== 'checkbox' ? isFormVisible = true : '', goToStep($event, false, true)]"
/>
2023-05-25 22:47:52 +03:00
<FieldAreas
2026-04-17 14:49:14 +03:00
v-if="!withAccessibilityAreas && !isAccessibilityMode"
2023-05-25 22:47:52 +03:00
ref="areas"
2023-06-16 00:04:05 +03:00
:steps="stepFields"
2023-05-25 22:47:52 +03:00
:values="values"
2024-07-19 09:40:56 +03:00
:with-field-placeholder="withFieldPlaceholder"
2024-07-24 20:55:35 +03:00
:submitter="submitter"
2024-07-22 17:42:29 +03:00
:scroll-el="scrollEl"
2024-07-24 20:55:35 +03:00
:with-signature-id="withSignatureId"
2023-05-25 22:47:52 +03:00
:attachments-index="attachmentsIndex"
2025-12-16 11:38:37 +02:00
:with-label="withFieldLabels && !isAnonymousChecboxes && showFieldNames"
2023-06-16 00:04:05 +03:00
:current-step="currentStepFields"
2024-07-02 20:27:25 +03:00
:scroll-padding="scrollPadding"
2025-04-18 13:02:17 +03:00
@focus-step="[saveStep(), currentField.type !== 'checkbox' ? isFormVisible = true : '', goToStep($event, false, true)]"
2023-05-25 22:47:52 +03:00
/>
2024-09-04 00:29:38 +03:00
<FieldAreas
2026-04-17 14:49:14 +03:00
v-if="!withAccessibilityAreas && !isAccessibilityMode"
2024-09-04 00:29:38 +03:00
:steps="readonlyConditionalFields.map((e) => [e])"
2025-01-09 12:26:56 +02:00
:values="readonlyConditionalFieldValues"
2024-09-04 00:29:38 +03:00
:submitter="submitter"
2024-12-06 00:47:40 +02:00
:attachments-index="attachmentsIndex"
2024-09-04 00:29:38 +03:00
:submittable="false"
/>
2024-02-24 01:01:36 +02:00
<FormulaFieldAreas
2026-04-17 14:49:14 +03:00
v-if="!withAccessibilityAreas && !isAccessibilityMode && formulaFields.length"
2024-02-24 01:01:36 +02:00
:fields="formulaFields"
2025-09-25 13:12:36 +03:00
:readonly-values="readonlyFieldValues"
2024-02-24 01:01:36 +02:00
:values="values"
/>
2024-11-07 20:58:43 +02:00
<Teleport
v-if="completeButtonToRef"
:to="completeButtonToRef"
>
<span
v-if="(emptyValueRequiredStep && ((stepFields.length - 1) !== currentStep || currentStepFields !== emptyValueRequiredStep)) || isCompleted"
class="tooltip-left"
:class="{ tooltip: !isCompleted }"
:data-tip="t('fill_all_required_fields_to_complete')"
>
<button
class="btn btn-sm btn-neutral text-white px-4 w-full flex justify-center btn-disabled pointer-events-auto"
@click="[isFormVisible = true, !isCompleted && goToStep(stepFields.indexOf(emptyValueRequiredStep), true, false)]"
>
{{ t('complete') }}
</button>
</span>
<button
v-else
id="complete_form_button"
class="btn btn-sm btn-neutral text-white px-4 w-full flex justify-center"
2026-05-31 09:09:57 +03:00
form="complete_form"
2024-11-07 20:58:43 +02:00
type="submit"
name="completed"
value="true"
:disabled="isSubmittingComplete"
>
<span class="flex items-center">
<IconInnerShadowTop
v-if="isSubmittingComplete"
class="mr-1 animate-spin w-5 h-5"
2026-04-16 12:41:42 +03:00
aria-hidden="true"
2024-11-07 20:58:43 +02:00
/>
<span>
{{ t('complete') }}
</span>
</span>
</button>
</Teleport>
2026-05-07 16:49:03 +03:00
<Teleport
2026-05-12 21:38:15 +03:00
v-for="ref in (showCompleteButton ? [completeButtonContainer, completeButtonScrollContainer].filter(Boolean) : [])"
2026-05-07 16:49:03 +03:00
:key="ref"
:to="ref"
>
<button
2026-05-12 21:38:15 +03:00
class="complete-button btn btn-sm btn-neutral text-white px-4"
2026-05-31 09:09:57 +03:00
form="complete_form"
2026-05-07 16:49:03 +03:00
type="submit"
name="completed"
value="true"
:disabled="isSubmittingComplete"
>
<span class="flex items-center">
<IconInnerShadowTop
v-if="isSubmittingComplete"
class="mr-1 animate-spin w-5 h-5"
aria-hidden="true"
/>
<span>
{{ t('complete') }}
</span>
</span>
</button>
</Teleport>
2026-05-31 09:09:57 +03:00
<form
v-if="!isCompleted && !isInvite"
id="complete_form"
class="hidden"
:action="submitPath"
method="post"
@submit.prevent="submitStep"
/>
2023-07-17 22:48:01 +03:00
<button
2026-07-04 15:47:40 +03:00
v-if="!isFormVisible && currentField"
2023-12-28 16:59:50 +02:00
id="expand_form_button"
2025-07-14 12:53:15 +03:00
class="btn btn-neutral flex text-white absolute bottom-0 w-full mb-3 expand-form-button text-base"
2024-04-20 18:25:24 +03:00
style="width: 96%; margin-left: 2%"
2026-01-20 15:27:35 +02:00
@click.prevent="[isFormVisible = true, $nextTick(() => scrollIntoField(currentField))]"
2023-07-17 22:48:01 +03:00
>
2024-02-28 01:54:10 +02:00
<template v-if="['initials', 'signature'].includes(currentField.type)">
<IconWritingSign stroke-width="1.5" />
{{ t('sign_now') }}
</template>
2024-04-20 18:25:24 +03:00
<template v-else-if="alwaysMinimize">
{{ t('next') }}
</template>
2024-09-20 23:53:33 +03:00
<template v-else-if="isShowContinue">
2024-09-18 15:46:39 +03:00
{{ t('continue') }}
</template>
2024-02-28 01:54:10 +02:00
<template v-else>
2024-09-18 15:46:39 +03:00
{{ t('start_now') }}
2024-02-28 01:54:10 +02:00
</template>
2023-07-17 22:48:01 +03:00
<IconArrowsDiagonal
class="absolute right-0 mr-4"
:width="20"
:height="20"
2026-04-16 12:41:42 +03:00
aria-hidden="true"
2023-07-17 22:48:01 +03:00
/>
</button>
<div
2026-07-04 15:47:40 +03:00
v-if="currentField"
2023-07-22 14:31:13 +03:00
v-show="isFormVisible"
2023-07-17 22:48:01 +03:00
id="form_container"
2025-05-16 18:28:55 +03:00
class="shadow-md bg-base-100 absolute bottom-0 w-full border-base-200 border p-4 rounded form-container overflow-hidden"
2024-01-03 18:12:35 +02:00
:class="{ 'md:bottom-4': isBreakpointMd }"
2023-08-28 23:43:33 +03:00
:style="{ backgroundColor: backgroundColor }"
2023-07-17 22:48:01 +03:00
>
<button
2023-06-16 23:39:55 +03:00
v-if="!isCompleted"
2023-12-28 16:59:50 +02:00
id="minimize_form_button"
2025-03-18 17:34:11 +02:00
class="absolute right-0 top-0 minimize-form-button"
2025-02-06 13:49:09 +02:00
:class="currentField?.description?.length > 100 ? 'mr-1 mt-1 md:mr-2 md:mt-2': 'mr-2 mt-2 hidden md:block'"
2024-02-19 23:52:47 +02:00
:title="t('minimize')"
2026-04-16 12:41:42 +03:00
:aria-label="t('minimize')"
2024-09-20 23:53:33 +03:00
@click.prevent="minimizeForm"
2023-05-25 22:47:52 +03:00
>
2023-07-17 22:48:01 +03:00
<IconArrowsDiagonalMinimize2
:width="20"
:height="20"
2026-04-16 12:41:42 +03:00
aria-hidden="true"
2023-07-17 22:48:01 +03:00
/>
</button>
2024-02-15 00:58:47 +02:00
<div
:class="{ 'md:px-4': isBreakpointMd }"
>
2023-07-17 22:48:01 +03:00
<form
2024-09-12 23:15:10 +03:00
v-if="!isCompleted && !isInvite"
2024-11-07 20:58:43 +02:00
id="steps_form"
2023-07-17 22:48:01 +03:00
ref="form"
:action="submitPath"
method="post"
2025-03-18 17:34:11 +02:00
class="mx-auto steps-form"
2024-02-15 00:58:47 +02:00
:style="{ maxWidth: isBreakpointMd ? '582px' : '' }"
2023-07-17 22:48:01 +03:00
@submit.prevent="submitStep"
2023-06-16 23:39:55 +03:00
>
2023-07-17 22:48:01 +03:00
<input
type="hidden"
name="authenticity_token"
:value="authenticityToken"
>
<input
value="put"
name="_method"
type="hidden"
>
2025-12-07 15:31:20 +02:00
<input
v-if="validate === false"
value="false"
name="validate"
type="hidden"
>
2023-07-17 22:48:01 +03:00
<div class="md:mt-4">
<div v-if="['cells', 'text'].includes(currentField.type)">
2023-10-16 00:41:14 +03:00
<TextStep
:key="currentField.uuid"
v-model="values[currentField.uuid]"
2024-01-24 23:20:53 +02:00
:show-field-names="showFieldNames"
2023-10-16 00:41:14 +03:00
:field="currentField"
2024-01-06 17:21:15 +02:00
@focus="scrollIntoField(currentField)"
2023-07-17 22:48:01 +03:00
/>
2023-06-16 23:39:55 +03:00
</div>
2024-02-23 15:58:49 +02:00
<NumberStep
v-else-if="currentField.type === 'number'"
:key="currentField.uuid"
v-model="values[currentField.uuid]"
:show-field-names="showFieldNames"
:field="currentField"
@focus="scrollIntoField(currentField)"
/>
2023-10-26 21:26:08 +03:00
<DateStep
v-else-if="currentField.type === 'date'"
:key="currentField.uuid"
v-model="values[currentField.uuid]"
2024-01-24 23:20:53 +02:00
:show-field-names="showFieldNames"
2023-10-26 21:26:08 +03:00
:field="currentField"
2024-10-11 20:17:50 +03:00
@submit="!isSubmitting && submitStep()"
2024-01-06 17:21:15 +02:00
@focus="scrollIntoField(currentField)"
2023-10-26 21:26:08 +03:00
/>
2023-07-17 22:48:01 +03:00
<div v-else-if="currentField.type === 'select'">
<label
2024-03-09 18:24:21 +02:00
v-if="showFieldNames && (currentField.name || currentField.title)"
2023-07-17 22:48:01 +03:00
:for="currentField.uuid"
2024-01-07 14:19:21 +02:00
dir="auto"
2025-03-18 17:34:11 +02:00
class="label text-xl sm:text-2xl py-0 mb-2 sm:mb-3.5 field-name-label"
2024-03-09 18:24:21 +02:00
:class="{ 'mb-2': !currentField.description }"
>
<MarkdownContent
v-if="currentField.title"
:string="currentField.title"
/>
<template v-else>
{{ currentField.name }}
</template>
<template v-if="!currentField.required">
2025-02-02 12:30:01 +02:00
<span :class="{ 'hidden sm:inline': (currentField.title || currentField.name).length > 20 }">
({{ t('optional') }})
</span>
2024-03-09 18:24:21 +02:00
</template>
2023-07-17 22:48:01 +03:00
</label>
<div
v-else
class="py-1"
/>
2024-03-09 18:24:21 +02:00
<div
v-if="currentField.description"
2026-04-16 12:41:42 +03:00
:id="currentField.uuid + '-desc'"
2024-03-09 18:24:21 +02:00
dir="auto"
2025-03-18 17:34:11 +02:00
class="mb-3 px-1 field-description-text"
2024-03-09 18:24:21 +02:00
>
<MarkdownContent :string="currentField.description" />
</div>
2024-01-06 17:21:15 +02:00
<AppearsOn :field="currentField" />
2023-07-17 22:48:01 +03:00
<select
2023-06-16 23:39:55 +03:00
:id="currentField.uuid"
2024-01-07 14:19:21 +02:00
dir="auto"
2023-06-16 23:39:55 +03:00
:required="currentField.required"
2026-06-25 15:26:52 +03:00
:aria-label="showFieldNames && (currentField.name || currentField.title) ? undefined : (currentField.name || currentField.title || t('select_your_option'))"
2026-04-16 12:41:42 +03:00
:aria-describedby="currentField.description ? currentField.uuid + '-desc' : undefined"
2023-07-17 22:48:01 +03:00
class="select base-input !text-2xl w-full text-center font-normal"
2024-10-10 19:49:31 +03:00
:class="{ 'text-gray-300': !values[currentField.uuid] }"
2023-06-16 23:39:55 +03:00
:name="`values[${currentField.uuid}]`"
2023-07-17 22:48:01 +03:00
@change="values[currentField.uuid] = $event.target.value"
2024-01-06 17:21:15 +02:00
@focus="scrollIntoField(currentField)"
2023-06-16 23:39:55 +03:00
>
2023-07-17 22:48:01 +03:00
<option
value=""
:selected="!values[currentField.uuid]"
2024-10-10 19:49:31 +03:00
class="text-gray-300"
2023-07-17 22:48:01 +03:00
>
2023-08-30 02:00:55 +03:00
{{ t('select_your_option') }}
2023-07-17 22:48:01 +03:00
</option>
<option
2023-11-13 01:46:28 +02:00
v-for="option in currentField.options"
:key="option.uuid"
:selected="values[currentField.uuid] == option.value"
:value="option.value"
2024-10-10 19:49:31 +03:00
class="text-base-content"
2023-07-17 22:48:01 +03:00
>
2023-11-13 01:46:28 +02:00
{{ option.value }}
2023-07-17 22:48:01 +03:00
</option>
</select>
2023-06-16 23:39:55 +03:00
</div>
2023-07-17 22:48:01 +03:00
<div v-else-if="currentField.type === 'radio'">
<label
2024-03-09 18:24:21 +02:00
v-if="showFieldNames && (currentField.name || currentField.title)"
2026-06-23 09:09:31 +03:00
:id="currentField.uuid + '-radio-label'"
2024-01-07 14:19:21 +02:00
dir="auto"
2025-03-18 17:34:11 +02:00
class="label text-xl sm:text-2xl py-0 mb-2 sm:mb-3.5 field-name-label"
2024-03-09 18:24:21 +02:00
:class="{ 'mb-2': !currentField.description }"
>
<MarkdownContent
v-if="currentField.title"
:string="currentField.title"
/>
<template v-else>
{{ currentField.name }}
</template>
<template v-if="!currentField.required">
2025-02-02 12:30:01 +02:00
<span :class="{ 'hidden sm:inline': (currentField.title || currentField.name).length > 20 }">
({{ t('optional') }})
</span>
2024-03-09 18:24:21 +02:00
</template>
2023-07-17 22:48:01 +03:00
</label>
2024-03-09 18:24:21 +02:00
<div
v-if="currentField.description"
2026-04-16 12:41:42 +03:00
:id="currentField.uuid + '-desc'"
2024-03-09 18:24:21 +02:00
dir="auto"
2025-03-18 17:34:11 +02:00
class="mb-3 px-1 field-description-text"
2024-03-09 18:24:21 +02:00
>
<MarkdownContent :string="currentField.description" />
</div>
2024-01-24 23:20:53 +02:00
<div class="flex w-full max-h-44 overflow-y-auto">
2024-01-24 22:28:45 +02:00
<div
2024-01-24 23:20:53 +02:00
v-if="!showFieldNames || (currentField.options.every((e) => !e.value) && currentField.options.length > 4)"
class="text-xl px-1"
2024-01-24 22:28:45 +02:00
>
<span
@click="scrollIntoField(currentField)"
>
2024-09-21 11:07:59 +03:00
{{ t('complete_hightlighted_checkboxes_and_click') }} <span class="font-semibold">{{ submitButtonText }}</span>.
2024-01-24 22:28:45 +02:00
</span>
</div>
<div
class="space-y-3.5 mx-auto"
2026-06-23 09:09:31 +03:00
role="radiogroup"
:aria-labelledby="(currentField.name || currentField.title) ? currentField.uuid + '-radio-label' : null"
2024-01-24 23:20:53 +02:00
:class="{ hidden: !showFieldNames || (currentField.options.every((e) => !e.value) && currentField.options.length > 4) }"
2024-01-24 22:28:45 +02:00
>
2023-07-17 22:48:01 +03:00
<div
2024-01-06 15:05:15 +02:00
v-for="(option, index) in currentField.options"
2023-11-13 01:46:28 +02:00
:key="option.uuid"
2023-07-17 22:48:01 +03:00
>
<label
2023-11-13 01:46:28 +02:00
:for="option.uuid"
2025-03-18 17:34:11 +02:00
class="flex items-center space-x-3 radio-label"
2023-07-17 22:48:01 +03:00
>
<input
2023-11-13 01:46:28 +02:00
:id="option.uuid"
2023-07-17 22:48:01 +03:00
v-model="values[currentField.uuid]"
type="radio"
class="base-radio !h-7 !w-7"
:name="`values[${currentField.uuid}]`"
2024-01-06 15:05:15 +02:00
:value="option.value || `${t('option')} ${index + 1}`"
2023-07-17 22:48:01 +03:00
:required="currentField.required"
2024-03-27 18:24:35 +02:00
@click="scrollIntoField(currentField)"
2023-07-17 22:48:01 +03:00
>
<span class="text-xl">
2024-01-06 15:05:15 +02:00
{{ option.value || `${t('option')} ${index + 1}` }}
2023-07-17 22:48:01 +03:00
</span>
</label>
</div>
</div>
</div>
</div>
<MultiSelectStep
v-else-if="currentField.type === 'multiple'"
2023-10-16 00:51:08 +03:00
:key="currentField.uuid"
2023-07-17 22:48:01 +03:00
v-model="values[currentField.uuid]"
2024-01-24 23:20:53 +02:00
:show-field-names="showFieldNames"
2024-01-24 22:28:45 +02:00
:is-last-step="stepFields.length === currentStep + 1"
2023-07-17 22:48:01 +03:00
:field="currentField"
2023-06-30 01:26:13 +03:00
/>
2023-07-17 22:48:01 +03:00
<div
v-else-if="currentField.type === 'checkbox'"
2023-05-25 22:47:52 +03:00
>
2024-03-09 18:24:21 +02:00
<div
v-if="currentField.description"
2026-04-16 12:41:42 +03:00
:id="currentField.uuid + '-desc'"
2024-03-09 18:24:21 +02:00
dir="auto"
2025-03-18 17:34:11 +02:00
class="mb-3 px-1 field-description-text"
2023-06-16 23:39:55 +03:00
>
2024-03-09 18:24:21 +02:00
<MarkdownContent :string="currentField.description" />
</div>
2023-07-17 22:48:01 +03:00
<div
2024-03-09 18:24:21 +02:00
class="flex w-full max-h-44 overflow-y-auto"
2023-06-16 23:39:55 +03:00
>
2024-03-09 18:24:21 +02:00
<input
type="hidden"
name="cast_boolean"
value="true"
>
<div
class="space-y-3.5 mx-auto"
>
<template v-if="isAnonymousChecboxes || !showFieldNames">
<span class="text-xl">
2024-09-21 11:07:59 +03:00
{{ t('complete_hightlighted_checkboxes_and_click') }} <span class="font-semibold">{{ submitButtonText }}</span>.
2024-03-09 18:24:21 +02:00
</span>
<input
v-for="field in currentStepFields"
:key="field.uuid"
type="hidden"
:name="`values[${field.uuid}]`"
:value="!!values[field.uuid]"
2023-06-16 23:39:55 +03:00
>
2024-03-09 18:24:21 +02:00
</template>
<template v-else>
<div
v-for="(field, index) in currentStepFields"
:key="field.uuid"
>
<label
:for="field.uuid"
2025-03-18 17:34:11 +02:00
class="flex items-center space-x-3 checkbox-label"
2024-01-13 13:15:08 +02:00
>
2024-03-09 18:24:21 +02:00
<input
type="hidden"
:name="`values[${field.uuid}]`"
:value="!!values[field.uuid]"
>
<input
:id="field.uuid"
type="checkbox"
class="base-checkbox !h-7 !w-7"
:required="field.required"
:checked="!!values[field.uuid]"
@click="[scrollIntoField(field), values[field.uuid] = !values[field.uuid]]"
>
<span
v-if="field.title"
class="text-xl"
>
<MarkdownContent :string="field.title" />
</span>
<span
v-else
class="text-xl"
>
{{ field.name || field.type + ' ' + (index + 1) }}
</span>
</label>
</div>
</template>
</div>
2023-06-16 23:39:55 +03:00
</div>
</div>
2023-07-17 22:48:01 +03:00
<ImageStep
2023-12-22 13:33:53 +02:00
v-else-if="currentField.type === 'image' || currentField.type === 'stamp'"
2023-10-16 00:51:08 +03:00
:key="currentField.uuid"
2023-07-17 22:48:01 +03:00
v-model="values[currentField.uuid]"
:field="currentField"
2024-07-02 20:27:25 +03:00
:dry-run="dryRun"
2023-07-17 22:48:01 +03:00
:attachments-index="attachmentsIndex"
:submitter-slug="submitterSlug"
2024-01-24 23:20:53 +02:00
:show-field-names="showFieldNames"
2024-01-06 17:21:15 +02:00
@attached="[attachments.push($event), scrollIntoField(currentField)]"
2023-07-17 22:48:01 +03:00
/>
<SignatureStep
v-else-if="currentField.type === 'signature'"
ref="currentStep"
2023-10-16 00:51:08 +03:00
:key="currentField.uuid"
2023-07-17 22:48:01 +03:00
v-model="values[currentField.uuid]"
2024-08-06 00:19:33 +03:00
:reason="values[currentField.preferences?.reason_field_uuid]"
2023-07-17 22:48:01 +03:00
:field="currentField"
2026-02-02 12:46:34 +02:00
:values="values"
2024-06-11 18:19:21 +03:00
:previous-value="previousSignatureValueFor(currentField) || previousSignatureValue"
2026-02-02 12:46:34 +02:00
:touch-attachment-uuid="previousSignatureValue"
:with-typed-signature="withTypedSignature"
2024-06-15 15:55:09 +03:00
:remember-signature="rememberSignature"
2023-07-17 22:48:01 +03:00
:attachments-index="attachmentsIndex"
2024-08-06 00:19:33 +03:00
:require-signing-reason="requireSigningReason"
2026-04-11 11:50:41 +03:00
:signature-text="signatureText"
:signature-src="signatureSrc"
2024-09-21 11:07:59 +03:00
:button-text="submitButtonText"
2024-07-02 20:27:25 +03:00
:dry-run="dryRun"
2024-05-12 12:08:18 +03:00
:with-disclosure="withDisclosure"
2024-06-02 14:50:37 +03:00
:with-qr-button="withQrButton"
2024-06-15 15:55:09 +03:00
:submitter="submitter"
2024-01-24 23:20:53 +02:00
:show-field-names="showFieldNames"
2024-08-06 00:19:33 +03:00
@update:reason="values[currentField.preferences?.reason_field_uuid] = $event"
2026-02-02 12:46:34 +02:00
@touch-attachment="attachmentsIndex[previousSignatureValue] ? attachmentsIndex[previousSignatureValue].created_at = new Date() : null"
2023-07-17 22:48:01 +03:00
@attached="attachments.push($event)"
2024-01-06 17:21:15 +02:00
@start="scrollIntoField(currentField)"
2024-09-20 23:53:33 +03:00
@minimize="minimizeForm"
2023-07-17 22:48:01 +03:00
/>
2023-09-20 00:13:14 +03:00
<InitialsStep
v-else-if="currentField.type === 'initials'"
ref="currentStep"
2023-10-16 00:51:08 +03:00
:key="currentField.uuid"
2023-09-20 00:13:14 +03:00
v-model="values[currentField.uuid]"
:field="currentField"
2024-07-02 20:27:25 +03:00
:dry-run="dryRun"
:submitter="submitter"
:previous-value="previousInitialsValue"
2023-09-20 00:13:14 +03:00
:attachments-index="attachmentsIndex"
2024-01-24 23:20:53 +02:00
:show-field-names="showFieldNames"
2023-09-20 00:13:14 +03:00
:submitter-slug="submitterSlug"
@attached="attachments.push($event)"
2024-01-06 17:21:15 +02:00
@start="scrollIntoField(currentField)"
@focus="scrollIntoField(currentField)"
2024-09-20 23:53:33 +03:00
@minimize="minimizeForm"
2023-09-20 00:13:14 +03:00
/>
2023-07-17 22:48:01 +03:00
<AttachmentStep
v-else-if="currentField.type === 'file'"
2023-10-16 00:51:08 +03:00
:key="currentField.uuid"
2023-07-17 22:48:01 +03:00
v-model="values[currentField.uuid]"
2024-07-02 20:27:25 +03:00
:dry-run="dryRun"
2023-07-17 22:48:01 +03:00
:field="currentField"
:attachments-index="attachmentsIndex"
:submitter-slug="submitterSlug"
2024-01-06 17:21:15 +02:00
@attached="[attachments.push($event), scrollIntoField(currentField)]"
2023-07-17 22:48:01 +03:00
/>
2023-09-05 01:00:21 +03:00
<PhoneStep
v-else-if="currentField.type === 'phone'"
ref="currentStep"
2023-10-16 00:51:08 +03:00
:key="currentField.uuid"
2023-09-05 01:00:21 +03:00
v-model="values[currentField.uuid]"
:field="currentField"
2024-04-23 21:33:40 +03:00
:locale="language?.toLowerCase() || browserLanguage"
2024-01-24 23:20:53 +02:00
:show-field-names="showFieldNames"
2024-04-20 17:07:31 +03:00
:verified-value="phoneVerifiedValues[currentField.uuid]"
2023-09-05 01:00:21 +03:00
:default-value="submitter.phone"
:submitter-slug="submitterSlug"
2024-01-06 17:21:15 +02:00
@focus="scrollIntoField(currentField)"
2024-10-11 20:17:50 +03:00
@submit="!isSubmitting && submitStep()"
2023-09-05 01:00:21 +03:00
/>
2023-12-14 21:22:26 +02:00
<PaymentStep
v-else-if="currentField.type === 'payment'"
ref="currentStep"
:key="currentField.uuid"
v-model="values[currentField.uuid]"
:field="currentField"
:submitter-slug="submitterSlug"
2025-09-25 13:12:36 +03:00
:fields="formulaFields"
2024-07-31 22:56:18 +03:00
:values="values"
2025-09-25 13:12:36 +03:00
:readonly-values="readonlyFieldValues"
2026-07-28 19:27:25 +03:00
:provider="paymentProvider"
2023-12-14 21:22:26 +02:00
@attached="attachments.push($event)"
2024-01-06 17:21:15 +02:00
@focus="scrollIntoField(currentField)"
2024-10-11 20:17:50 +03:00
@submit="!isSubmitting && submitStep()"
2023-12-14 21:22:26 +02:00
/>
2026-01-02 16:07:04 +02:00
<KbaStep
v-else-if="currentField.type === 'kba'"
ref="currentStep"
:key="currentField.uuid"
:submitter="submitter"
:empty-value-required-step="emptyValueRequiredStep"
:field="currentField"
:submitter-slug="submitterSlug"
:values="values"
@submit="!isSubmitting && submitStep()"
/>
2024-12-01 00:10:07 +02:00
<VerificationStep
v-else-if="currentField.type === 'verification'"
ref="currentStep"
:key="currentField.uuid"
:locale="language?.toLowerCase() || browserLanguage"
:submitter="submitter"
:empty-value-required-step="emptyValueRequiredStep"
:field="currentField"
:submitter-slug="submitterSlug"
:values="values"
@focus="scrollIntoField(currentField)"
@submit="!isSubmitting && submitStep()"
/>
2023-06-16 23:39:55 +03:00
</div>
2023-12-14 21:22:26 +02:00
<div
2026-01-02 16:07:04 +02:00
v-if="(currentField.type !== 'payment' && currentField.type !== 'verification' && currentField.type !== 'kba') || submittedValues[currentField.uuid]"
2025-02-02 12:30:01 +02:00
:class="currentField.type === 'signature' ? 'mt-2' : 'mt-4 md:mt-6'"
2023-12-14 21:22:26 +02:00
>
2023-07-17 22:48:01 +03:00
<button
2023-12-28 16:59:50 +02:00
id="submit_form_button"
2023-10-15 21:41:47 +03:00
ref="submitButton"
2023-07-17 22:48:01 +03:00
type="submit"
2025-03-18 17:34:11 +02:00
class="base-button w-full flex justify-center submit-form-button"
2023-07-17 22:48:01 +03:00
:disabled="isButtonDisabled"
2023-05-25 22:47:52 +03:00
>
2023-07-17 22:48:01 +03:00
<span class="flex">
<IconInnerShadowTop
v-if="isSubmitting"
class="mr-1 animate-spin"
2026-04-16 12:41:42 +03:00
aria-hidden="true"
2023-07-17 22:48:01 +03:00
/>
2024-05-18 22:54:26 +03:00
<span>
2024-09-21 11:07:59 +03:00
{{ submitButtonText }}
2023-07-17 22:48:01 +03:00
</span><span
v-if="isSubmitting"
class="w-6 flex justify-start mr-1"
><span>...</span></span>
2023-06-20 00:24:39 +03:00
</span>
2023-07-17 22:48:01 +03:00
</button>
2023-10-15 21:41:47 +03:00
<div
v-if="showFillAllRequiredFields"
2026-04-16 12:41:42 +03:00
role="alert"
2023-10-15 21:41:47 +03:00
class="text-center mt-1"
>
{{ t('please_fill_all_required_fields') }}
</div>
2023-07-17 22:48:01 +03:00
</div>
</form>
2024-09-12 17:31:37 +03:00
<InviteForm
2024-09-12 23:15:10 +03:00
v-else-if="isInvite"
2024-09-12 17:31:37 +03:00
:submitters="inviteSubmitters"
2024-12-19 17:17:34 +02:00
:optional-submitters="optionalInviteSubmitters"
2026-02-14 18:10:16 +02:00
:fetch-options="fetchOptions"
2024-09-12 17:31:37 +03:00
:submitter-slug="submitterSlug"
:authenticity-token="authenticityToken"
:url="baseUrl + submitPath + '/invite'"
:style="{ maxWidth: isBreakpointMd ? '582px' : '' }"
2024-09-12 23:15:10 +03:00
@success="[isInvite = false, performComplete($event)]"
2024-09-12 17:31:37 +03:00
/>
2023-07-17 22:48:01 +03:00
<FormCompleted
v-else
:is-demo="isDemo"
2023-09-03 20:44:54 +03:00
:attribution="attribution"
2024-09-18 15:46:39 +03:00
:has-signature-fields="stepFields.some((fields) => fields.some((f) => ['signature', 'initials'].includes(f.type)))"
:has-multiple-documents="hasMultipleDocuments"
2024-01-14 12:11:13 +02:00
:completed-button="completedRedirectUrl ? {} : completedButton"
2026-02-14 18:10:16 +02:00
:fetch-options="fetchOptions"
2024-04-05 16:16:30 +03:00
:completed-message="completedRedirectUrl ? {} : completedMessage"
2024-01-14 12:11:13 +02:00
:with-send-copy-button="withSendCopyButton && !completedRedirectUrl"
2024-07-02 20:27:25 +03:00
:with-download-button="withDownloadButton && !completedRedirectUrl && !dryRun"
2023-08-12 12:34:02 +03:00
:with-confetti="withConfetti"
2023-09-05 01:00:21 +03:00
:can-send-email="canSendEmail && !!submitter.email"
2023-07-17 22:48:01 +03:00
:submitter-slug="submitterSlug"
/>
2026-04-16 12:41:42 +03:00
<nav
2023-12-31 17:23:27 +02:00
v-if="stepFields.length < 80"
2026-04-16 12:41:42 +03:00
:aria-label="t('form_progress')"
2026-04-17 14:49:14 +03:00
:aria-hidden="isCompleted"
2025-12-15 10:22:27 +02:00
class="flex justify-center mt-3 sm:mt-4 mb-0 sm:mb-1 select-none"
2023-12-31 17:23:27 +02:00
>
2025-03-18 17:34:11 +02:00
<div class="flex items-center flex-wrap steps-progress">
2026-02-04 10:51:11 +02:00
<template
2023-07-17 22:48:01 +03:00
v-for="(step, index) in stepFields"
:key="step[0].uuid"
2026-02-04 10:51:11 +02:00
>
2026-04-16 12:41:42 +03:00
<button
2026-02-04 10:51:11 +02:00
v-if="!onlyRequiredFields || step.some((f) => f.required)"
2026-04-16 12:41:42 +03:00
type="button"
:aria-label="`${t('step')} ${index + 1}`"
:aria-current="index === currentStep ? 'step' : undefined"
class="inline border border-base-300 h-3 w-3 rounded-full mx-1 mt-1 p-0"
2026-02-04 10:51:11 +02:00
:class="{ 'bg-base-300 steps-progress-current': index === currentStep, 'bg-base-content': (index < currentStep && stepFields[index].every((f) => !f.required || ![null, undefined, ''].includes(values[f.uuid]))) || isCompleted, 'bg-white': index > currentStep }"
2026-04-16 12:41:42 +03:00
@click="isCompleted ? '' : [saveStep(), goToStep(index, true)]"
2026-02-04 10:51:11 +02:00
/>
</template>
2023-07-17 22:48:01 +03:00
</div>
2026-04-16 12:41:42 +03:00
</nav>
2023-12-31 17:23:27 +02:00
<div
v-else
class="mt-5"
/>
2023-06-15 01:05:04 +03:00
</div>
2023-06-16 23:39:55 +03:00
</div>
2023-05-25 22:47:52 +03:00
</template>
<script>
import FieldAreas from './areas'
2024-02-24 01:01:36 +02:00
import FormulaFieldAreas from './formula_areas'
2026-04-17 14:49:14 +03:00
import AccessibilityAreas from './accessibility_areas'
2023-05-25 22:47:52 +03:00
import ImageStep from './image_step'
import SignatureStep from './signature_step'
2023-09-20 00:13:14 +03:00
import InitialsStep from './initials_step'
2023-05-25 22:47:52 +03:00
import AttachmentStep from './attachment_step'
2023-06-16 00:04:05 +03:00
import MultiSelectStep from './multi_select_step'
2023-09-05 01:00:21 +03:00
import PhoneStep from './phone_step'
2023-12-14 21:22:26 +02:00
import PaymentStep from './payment_step'
2024-12-01 00:10:07 +02:00
import VerificationStep from './verification_step'
2026-01-02 16:07:04 +02:00
import KbaStep from './kba_step'
2023-10-16 00:41:14 +03:00
import TextStep from './text_step'
2024-02-23 15:58:49 +02:00
import NumberStep from './number_step'
2023-10-26 21:26:08 +03:00
import DateStep from './date_step'
2024-03-09 18:24:21 +02:00
import MarkdownContent from './markdown_content'
2024-09-12 17:31:37 +03:00
import InviteForm from './invite_form'
2023-05-25 22:47:52 +03:00
import FormCompleted from './completed'
2024-02-28 01:54:10 +02:00
import { IconInnerShadowTop, IconArrowsDiagonal, IconWritingSign, IconArrowsDiagonalMinimize2 } from '@tabler/icons-vue'
2024-01-06 17:21:15 +02:00
import AppearsOn from './appears_on'
2024-01-26 16:45:32 +02:00
import i18n from './i18n'
2025-08-20 21:22:59 +03:00
import { sanitizeUrl } from '@braintree/sanitize-url'
2023-05-25 22:47:52 +03:00
2026-01-26 12:17:57 +02:00
if (typeof URL.canParse !== 'function') {
URL.canParse = function (url, base) {
try {
const parsed = new URL(url, base)
return !!parsed
} catch {
return false
}
}
}
2024-02-23 15:58:49 +02:00
const isEmpty = (obj) => {
if (obj == null) return true
if (Array.isArray(obj)) {
2024-02-23 15:58:49 +02:00
return obj.length === 0
}
if (typeof obj === 'string') {
return obj.trim().length === 0
}
2024-02-23 15:58:49 +02:00
if (typeof obj === 'object') {
return Object.keys(obj).length === 0
}
if (obj === false) {
return true
}
return false
}
2023-05-25 22:47:52 +03:00
export default {
2023-05-31 23:19:20 +03:00
name: 'SubmissionForm',
2023-05-25 22:47:52 +03:00
components: {
FieldAreas,
2026-04-17 14:49:14 +03:00
AccessibilityAreas,
2023-05-25 22:47:52 +03:00
ImageStep,
SignatureStep,
2024-01-06 17:21:15 +02:00
AppearsOn,
2024-02-28 01:54:10 +02:00
IconWritingSign,
2023-05-25 22:47:52 +03:00
AttachmentStep,
2023-09-20 00:13:14 +03:00
InitialsStep,
2024-12-01 00:10:07 +02:00
VerificationStep,
2026-01-02 16:07:04 +02:00
KbaStep,
2024-09-12 17:31:37 +03:00
InviteForm,
2023-06-16 00:04:05 +03:00
MultiSelectStep,
2023-06-20 00:24:39 +03:00
IconInnerShadowTop,
2023-10-26 21:26:08 +03:00
DateStep,
2023-07-17 22:48:01 +03:00
IconArrowsDiagonal,
2023-10-16 00:41:14 +03:00
TextStep,
2024-02-23 15:58:49 +02:00
NumberStep,
2024-02-24 01:01:36 +02:00
FormulaFieldAreas,
2023-09-05 01:00:21 +03:00
PhoneStep,
2024-03-09 18:24:21 +02:00
MarkdownContent,
2023-12-14 21:22:26 +02:00
PaymentStep,
2023-07-17 22:48:01 +03:00
IconArrowsDiagonalMinimize2,
2023-05-25 22:47:52 +03:00
FormCompleted
},
2023-08-12 12:34:02 +03:00
provide () {
return {
2023-08-30 02:00:55 +03:00
baseUrl: this.baseUrl,
2024-01-06 17:21:15 +02:00
scrollIntoArea: this.scrollIntoArea,
2024-01-24 22:28:45 +02:00
scrollIntoField: this.scrollIntoField,
2023-08-30 02:00:55 +03:00
t: this.t
2023-08-12 12:34:02 +03:00
}
},
2023-05-25 22:47:52 +03:00
props: {
2023-09-03 14:05:31 +03:00
submitter: {
type: Object,
2023-06-13 00:29:07 +03:00
required: true
},
2024-09-12 17:31:37 +03:00
inviteSubmitters: {
type: Array,
required: false,
default: () => []
},
2026-02-14 18:10:16 +02:00
fetchOptions: {
type: Object,
required: false,
default: () => ({})
},
2024-12-19 17:17:34 +02:00
optionalInviteSubmitters: {
type: Array,
required: false,
default: () => []
},
2024-07-24 20:55:35 +03:00
withSignatureId: {
type: Boolean,
required: false,
default: false
},
2024-07-02 20:27:25 +03:00
scrollPadding: {
type: String,
required: false,
default: '-80px'
},
2024-12-20 13:31:24 +02:00
orderAsOnPage: {
type: Boolean,
required: false,
default: false
},
2026-02-04 10:51:11 +02:00
onlyRequiredFields: {
type: Boolean,
required: false,
default: false
},
2024-08-06 00:19:33 +03:00
requireSigningReason: {
type: Boolean,
required: false,
default: false
},
2023-06-30 20:31:17 +03:00
canSendEmail: {
type: Boolean,
required: false,
default: false
},
2024-11-07 20:58:43 +02:00
completeButtonToRef: {
type: Object,
required: false,
default: null
},
2026-05-12 21:38:15 +03:00
completeButtonContainer: {
2026-05-07 16:49:03 +03:00
type: Object,
required: false,
default: null
},
2026-05-12 21:38:15 +03:00
completeButtonScrollContainer: {
2026-05-07 16:49:03 +03:00
type: Object,
required: false,
default: null
},
2024-12-07 01:35:59 +02:00
schema: {
type: Array,
required: false,
default: () => []
},
2023-05-25 22:47:52 +03:00
attachments: {
type: Array,
required: false,
default: () => []
},
2024-07-19 09:40:56 +03:00
withFieldPlaceholder: {
type: Boolean,
required: false,
default: false
},
2024-07-22 17:42:29 +03:00
scrollEl: {
type: Object,
required: false,
default: null
},
2023-10-25 02:06:47 +03:00
onComplete: {
type: Function,
required: false,
default () {
return () => {}
}
},
2024-02-24 17:34:22 +02:00
expand: {
type: Boolean,
required: false,
2024-02-28 01:54:10 +02:00
default: null
2024-02-24 17:34:22 +02:00
},
2024-06-15 15:55:09 +03:00
rememberSignature: {
type: Boolean,
required: false,
default: false
},
2024-04-20 18:25:24 +03:00
minimize: {
type: Boolean,
required: false,
default: false
},
2025-12-07 15:31:20 +02:00
validate: {
type: Boolean,
required: false,
default: true
},
2024-05-12 12:08:18 +03:00
withDisclosure: {
type: Boolean,
required: false,
default: false
},
2024-04-25 17:51:36 +03:00
reuseSignature: {
type: Boolean,
required: false,
default: true
},
2025-12-16 11:38:37 +02:00
withFieldLabels: {
type: Boolean,
required: false,
default: true
},
2023-08-12 12:34:02 +03:00
withConfetti: {
type: Boolean,
required: false,
default: false
},
2024-04-08 18:34:27 +03:00
autoscrollFields: {
type: Boolean,
required: false,
default: true
},
2024-01-24 23:20:53 +02:00
showFieldNames: {
type: Boolean,
required: false,
default: true
},
2024-06-02 14:50:37 +03:00
withQrButton: {
type: Boolean,
required: false,
default: false
},
withTypedSignature: {
type: Boolean,
required: false,
default: true
},
2024-01-03 18:12:35 +02:00
isBreakpointMd: {
type: Boolean,
required: false,
default: true
},
2023-08-12 12:34:02 +03:00
baseUrl: {
type: String,
required: false,
default: ''
},
2026-04-17 14:49:14 +03:00
filledFieldsIndex: {
type: Object,
required: false,
default: null
},
withAccessibilityAreas: {
type: Boolean,
required: false,
default: null
},
2023-05-25 22:47:52 +03:00
fields: {
type: Array,
required: false,
default: () => []
},
2023-08-28 23:43:33 +03:00
backgroundColor: {
type: String,
2024-06-11 18:19:21 +03:00
required: false,
default: ''
},
2026-04-11 11:50:41 +03:00
signatureText: {
type: String,
required: false,
default: ''
},
signatureSrc: {
type: String,
required: false,
default: ''
},
2024-06-11 18:19:21 +03:00
previousSignatureValue: {
type: String,
2023-08-28 23:43:33 +03:00
required: false,
default: ''
},
2023-10-07 10:23:11 +03:00
allowToSkip: {
type: Boolean,
required: false,
2023-10-21 12:09:50 +03:00
default: false
2023-10-07 10:23:11 +03:00
},
2023-09-22 21:50:39 +03:00
goToLast: {
type: Boolean,
required: false,
default: true
},
2023-07-12 01:24:25 +03:00
isDemo: {
type: Boolean,
2023-08-12 12:34:02 +03:00
required: false,
2023-07-12 01:24:25 +03:00
default: false
},
2024-05-18 22:54:26 +03:00
dryRun: {
type: Boolean,
required: false,
default: false
},
2023-09-03 20:44:54 +03:00
attribution: {
type: Boolean,
required: false,
default: true
},
2024-01-26 16:45:32 +02:00
language: {
type: String,
required: false,
default: ''
},
2026-07-28 19:27:25 +03:00
paymentProvider: {
type: String,
required: false,
default: ''
},
2023-05-25 22:47:52 +03:00
values: {
type: Object,
required: false,
default: () => ({})
2023-09-29 01:24:39 +03:00
},
2024-03-23 23:16:40 +02:00
authenticityToken: {
type: String,
required: false,
default: ''
},
2024-02-15 22:13:14 +02:00
i18n: {
type: Object,
required: false,
default: () => ({})
},
2023-12-17 16:10:17 +02:00
withSendCopyButton: {
type: Boolean,
required: false,
default: true
},
withDownloadButton: {
type: Boolean,
required: false,
default: true
},
2024-01-14 12:11:13 +02:00
completedRedirectUrl: {
type: String,
required: false,
default: ''
},
2023-09-29 01:24:39 +03:00
completedButton: {
type: Object,
required: false,
default: () => ({})
2024-04-05 16:16:30 +03:00
},
completedMessage: {
type: Object,
required: false,
default: () => ({})
2023-05-25 22:47:52 +03:00
}
},
data () {
return {
isCompleted: false,
2024-09-12 23:15:10 +03:00
isInvite: false,
2024-02-28 01:54:10 +02:00
isFormVisible: this.expand !== false,
2023-10-15 21:41:47 +03:00
showFillAllRequiredFields: false,
2023-05-25 22:47:52 +03:00
currentStep: 0,
2024-09-20 23:53:33 +03:00
isShowContinue: false,
2024-06-27 17:41:08 +03:00
enableScrollIntoField: true,
2024-04-20 17:07:31 +03:00
phoneVerifiedValues: {},
2024-04-20 18:25:24 +03:00
orientation: screen?.orientation?.type,
2023-09-05 01:35:48 +03:00
isSubmitting: false,
2024-11-07 20:58:43 +02:00
isSubmittingComplete: false,
2023-09-27 23:28:33 +03:00
submittedValues: {},
2026-05-12 21:38:15 +03:00
isFormStarted: false,
2026-04-17 14:49:14 +03:00
recalculateButtonDisabledKey: '',
isAccessibilityMode: false
2023-05-25 22:47:52 +03:00
}
},
computed: {
2024-04-20 18:25:24 +03:00
isMobile () {
2025-01-11 14:02:04 +02:00
const isMobileSafariIos = 'ontouchstart' in window && navigator.maxTouchPoints > 0 && /AppleWebKit/i.test(navigator.userAgent)
2025-01-10 21:49:30 +02:00
return isMobileSafariIos || /android|iphone|ipad/i.test(navigator.userAgent)
2024-04-20 18:25:24 +03:00
},
2025-01-09 12:26:56 +02:00
readonlyConditionalFieldValues () {
return this.readonlyConditionalFields.reduce((acc, f) => {
2025-09-25 13:12:36 +03:00
acc[f.uuid] = isEmpty(this.values[f.uuid]) ? f.default_value : this.values[f.uuid]
return acc
}, {})
},
readonlyFieldValues () {
return this.readonlyFields.reduce((acc, f) => {
acc[f.uuid] = isEmpty(this.values[f.uuid]) ? f.default_value : this.values[f.uuid]
2025-01-09 12:26:56 +02:00
return acc
}, {})
},
2024-12-07 01:35:59 +02:00
attachmentConditionsIndex () {
2026-01-28 13:24:05 +02:00
const cache = {}
2024-12-07 01:35:59 +02:00
return this.schema.reduce((acc, item) => {
if (item.conditions?.length) {
if (item.conditions.every((c) => this.fieldsUuidIndex[c.field_uuid])) {
2026-01-28 13:24:05 +02:00
acc[item.attachment_uuid] = this.checkFieldConditions(item, cache)
2024-12-07 01:35:59 +02:00
} else {
acc[item.attachment_uuid] = true
}
} else {
acc[item.attachment_uuid] = true
}
return acc
}, {})
},
2024-11-07 20:58:43 +02:00
emptyValueRequiredStep () {
return this.stepFields.find((fields, index) => {
return fields.some((f) => {
return f.required && isEmpty(this.values[f.uuid])
})
})
},
2026-05-12 21:38:15 +03:00
showCompleteButton () {
return this.completeButtonContainer && !this.isCompleted && !this.isInvite && this.isFormStarted &&
!this.stepFields.find((fields) => fields.some((f) => f.required && isEmpty(this.submittedValues[f.uuid])))
2026-05-07 16:49:03 +03:00
},
2024-09-21 11:07:59 +03:00
submitButtonText () {
if (this.alwaysMinimize) {
2024-05-12 12:08:18 +03:00
return this.t('submit')
2026-02-04 10:51:11 +02:00
} else if (!this.onlyRequiredFields && this.stepFields.length === this.currentStep + 1) {
if (this.currentField.type === 'signature') {
return this.t('sign_and_complete')
} else {
return this.t('complete')
}
} else if (this.onlyRequiredFields && !this.findNextStep(this.currentStep)) {
2024-09-21 11:07:59 +03:00
if (this.currentField.type === 'signature') {
return this.t('sign_and_complete')
} else {
return this.t('complete')
}
2024-05-12 12:08:18 +03:00
} else {
return this.t('next')
}
},
2024-04-20 18:25:24 +03:00
alwaysMinimize () {
return this.minimize || (this.orientation?.includes('landscape') && this.isMobile && parseInt(window.innerHeight) < 550)
},
2024-09-18 15:46:39 +03:00
hasMultipleDocuments () {
return Object.keys(
this.stepFields.reduce((acc, fields) => {
fields.forEach((f) => {
f.areas?.forEach((a) => {
acc[a.attachment_uuid] = 1
})
})
return acc
}, {})
).filter(Boolean).length > 1
},
2023-06-16 00:04:05 +03:00
currentStepFields () {
2024-05-10 22:24:44 +03:00
return this.stepFields[this.currentStep] || []
2023-06-16 00:04:05 +03:00
},
2024-01-26 16:45:32 +02:00
browserLanguage () {
return (navigator.language || navigator.userLanguage || 'en').split('-')[0]
},
2023-12-14 21:22:26 +02:00
queryParams () {
return new URLSearchParams(window.location.search)
},
2023-09-03 14:05:31 +03:00
submitterSlug () {
return this.submitter.slug
},
2024-03-01 23:29:37 +02:00
fieldsUuidIndex () {
return this.fields.reduce((acc, f) => {
acc[f.uuid] = f
return acc
}, {})
},
previousInitialsValue () {
2024-04-25 17:51:36 +03:00
if (this.reuseSignature !== false) {
2026-01-30 09:58:30 +02:00
const initialsField = this.fields.findLast
? this.fields.findLast((field) => field.type === 'initials' && !!this.values[field.uuid])
: [...this.fields].reverse().find((field) => field.type === 'initials' && !!this.values[field.uuid])
2024-04-25 17:51:36 +03:00
return this.values[initialsField?.uuid]
} else {
return null
}
},
2023-07-31 00:48:51 +03:00
isAnonymousChecboxes () {
2026-07-04 15:47:40 +03:00
if (this.currentField) {
return this.currentField.type === 'checkbox' && this.currentStepFields.every((e) => !e.name && !e.required) && this.currentStepFields.length > 4
} else {
return false
}
2023-07-31 00:48:51 +03:00
},
2023-06-24 17:15:36 +03:00
isButtonDisabled () {
2023-09-05 01:35:48 +03:00
if (this.recalculateButtonDisabledKey) {
return this.isSubmitting ||
2024-01-06 15:37:57 +02:00
(this.currentField.required && ['image', 'file', 'multiple'].includes(this.currentField.type) && !this.values[this.currentField.uuid]?.length) ||
2023-09-20 00:13:14 +03:00
(this.currentField.required && this.currentField.type === 'signature' && !this.values[this.currentField.uuid]?.length && this.$refs.currentStep && !this.$refs.currentStep.isSignatureStarted) ||
(this.currentField.required && this.currentField.type === 'initials' && !this.values[this.currentField.uuid]?.length && this.$refs.currentStep && !this.$refs.currentStep.isInitialsStarted)
2023-09-05 01:35:48 +03:00
} else {
return false
}
2023-06-24 17:15:36 +03:00
},
2023-05-25 22:47:52 +03:00
currentField () {
2023-06-16 00:04:05 +03:00
return this.currentStepFields[0]
2023-06-13 00:29:07 +03:00
},
2024-09-04 00:29:38 +03:00
readonlyConditionalFields () {
2025-09-25 13:12:36 +03:00
return this.readonlyFields.filter((f) => f.conditions?.length)
},
readonlyFields () {
2026-01-28 13:24:05 +02:00
const cache = {}
return this.fields.filter((f) => f.readonly && this.checkFieldConditions(f, cache) && this.checkFieldDocumentsConditions(f))
2024-09-04 00:29:38 +03:00
},
2023-06-16 00:04:05 +03:00
stepFields () {
2024-12-01 00:10:07 +02:00
const verificationFields = []
const sortedFields = this.fields.reduce((acc, f) => {
2026-01-02 16:07:04 +02:00
if (f.type === 'verification' || f.type === 'kba') {
2024-12-01 00:10:07 +02:00
verificationFields.push(f)
} else if (!f.readonly) {
acc.push(f)
}
return acc
}, [])
2024-12-20 13:31:24 +02:00
if (this.orderAsOnPage) {
const fieldAreasIndex = {}
const attachmentUuids = Object.keys(this.attachmentConditionsIndex)
const sortArea = (aArea, bArea) => {
if (aArea.attachment_uuid === bArea.attachment_uuid) {
if (aArea.page === bArea.page) {
if (Math.abs(aArea.y - bArea.y) < 0.01) {
if (aArea.x === bArea.x) {
return 0
} else {
return aArea.x - bArea.x
}
} else {
return aArea.y - bArea.y
}
} else {
return aArea.page - bArea.page
}
} else {
return attachmentUuids.indexOf(aArea.attachment_uuid) - attachmentUuids.indexOf(bArea.attachment_uuid)
}
}
sortedFields.sort((aField, bField) => {
const aArea = (fieldAreasIndex[aField.uuid] ||= [...(aField.areas || [])].sort(sortArea)[0])
const bArea = (fieldAreasIndex[bField.uuid] ||= [...(bField.areas || [])].sort(sortArea)[0])
2025-09-04 16:13:29 +03:00
if (aArea && bArea) {
return sortArea(aArea, bArea)
} else {
return 0
}
2024-12-20 13:31:24 +02:00
})
}
2024-12-01 00:10:07 +02:00
if (verificationFields.length) {
sortedFields.push(verificationFields.pop())
}
2026-01-28 13:24:05 +02:00
const cache = {}
2024-12-01 00:10:07 +02:00
return sortedFields.reduce((acc, f) => {
2023-06-16 00:04:05 +03:00
const prevStep = acc[acc.length - 1]
2026-01-28 13:24:05 +02:00
if (this.checkFieldConditions(f, cache) && this.checkFieldDocumentsConditions(f)) {
2024-03-09 18:24:21 +02:00
if (f.type === 'checkbox' && Array.isArray(prevStep) && prevStep[0].type === 'checkbox' && !f.description) {
2024-03-01 23:29:37 +02:00
prevStep.push(f)
} else {
acc.push([f])
}
2023-06-16 00:04:05 +03:00
}
return acc
}, [])
},
2024-02-24 01:01:36 +02:00
formulaFields () {
2026-01-28 13:24:05 +02:00
const cache = {}
return this.fields.filter((f) => f.preferences?.formula && f.type !== 'payment' && this.checkFieldConditions(f, cache) && this.checkFieldDocumentsConditions(f))
2024-02-24 01:01:36 +02:00
},
2023-05-25 22:47:52 +03:00
attachmentsIndex () {
return this.attachments.reduce((acc, a) => {
acc[a.uuid] = a
return acc
}, {})
},
submitPath () {
2023-06-13 00:29:07 +03:00
return `/s/${this.submitterSlug}`
2023-05-25 22:47:52 +03:00
}
},
2024-02-24 17:34:22 +02:00
watch: {
expand (value) {
this.isFormVisible = value
2024-04-20 17:23:28 +03:00
},
currentStepFields (value) {
2024-05-23 12:45:01 +03:00
if (isEmpty(value) && this.currentStep > 0) {
2024-04-20 17:23:28 +03:00
this.currentStep -= 1
}
2024-12-07 01:35:59 +02:00
},
attachmentConditionsIndex: {
deep: true,
immediate: true,
handler (value) {
this.$nextTick(() => {
const root = this.$root.$el.parentNode.getRootNode()
for (const key in value) {
const doc = root.querySelector(`[id="document-${key}"`)
if (doc) {
doc.classList.toggle('hidden', !value[key])
}
}
})
}
2024-02-24 17:34:22 +02:00
}
},
2024-04-20 18:25:24 +03:00
beforeUnmount () {
screen?.orientation?.removeEventListener('change', this.onOrientationChange)
},
2023-05-25 22:47:52 +03:00
mounted () {
2023-09-27 23:28:33 +03:00
this.submittedValues = JSON.parse(JSON.stringify(this.values))
2024-10-05 14:48:37 +03:00
screen?.orientation?.addEventListener('change', this.onOrientationChange)
2024-04-20 18:25:24 +03:00
2023-11-05 01:41:54 +02:00
this.fields.forEach((field) => {
if (field.default_value && !field.readonly) {
2024-02-08 20:12:08 +02:00
this.values[field.uuid] ||= field.default_value
2023-11-05 01:41:54 +02:00
}
})
2023-12-14 21:22:26 +02:00
if (this.queryParams.get('field_uuid')) {
const stepIndex = this.stepFields.findIndex((fields) => {
return fields.some((f) => f.uuid === this.queryParams.get('field_uuid'))
})
this.currentStep = Math.max(stepIndex, 0)
} else if (this.goToLast) {
2023-11-05 01:41:54 +02:00
const requiredEmptyStepIndex = this.stepFields.indexOf(this.stepFields.find((fields) => fields.some((f) => f.required && !this.submittedValues[f.uuid])))
2026-01-30 09:58:30 +02:00
const lastFilledStepIndex = this.stepFields.indexOf(this.stepFields.findLast
? this.stepFields.findLast((fields) => fields.some((f) => !!this.submittedValues[f.uuid]))
: [...this.stepFields].reverse().find((fields) => fields.some((f) => !!this.submittedValues[f.uuid]))) + 1
2023-10-15 21:41:47 +03:00
const indexesList = [this.stepFields.length - 1]
2026-02-04 10:51:11 +02:00
if (requiredEmptyStepIndex !== -1 && (!this.onlyRequiredFields || this.stepFields[requiredEmptyStepIndex].some((f) => f.required))) {
2023-10-15 21:41:47 +03:00
indexesList.push(requiredEmptyStepIndex)
}
2026-02-04 10:51:11 +02:00
if (lastFilledStepIndex !== -1 && (!this.onlyRequiredFields || this.stepFields[lastFilledStepIndex].some((f) => f.required))) {
2023-10-15 21:41:47 +03:00
indexesList.push(lastFilledStepIndex)
}
this.currentStep = Math.min(...indexesList)
2023-09-22 21:50:39 +03:00
}
2023-07-03 00:03:29 +03:00
2024-02-28 01:54:10 +02:00
if (document.body?.clientWidth >= 768 && this.expand !== true && ['signature', 'initials', 'file', 'image'].includes(this.currentField?.type)) {
2024-09-20 23:53:33 +03:00
this.minimizeForm()
2024-02-28 01:54:10 +02:00
}
2024-04-20 18:25:24 +03:00
if (this.alwaysMinimize) {
2024-09-20 23:53:33 +03:00
this.minimizeForm()
2024-04-20 18:25:24 +03:00
}
2025-01-17 01:37:23 +02:00
const isMobile = 'ontouchstart' in window && navigator.maxTouchPoints > 0 && /AppleWebKit|android/i.test(navigator.userAgent)
2025-01-10 21:49:30 +02:00
2025-01-17 01:37:23 +02:00
if (isMobile || /iPhone|iPad|iPod/i.test(navigator.userAgent)) {
2023-08-12 12:34:02 +03:00
this.$nextTick(() => {
const root = this.$root.$el.parentNode.getRootNode()
const scrollbox = root.getElementById('scrollbox')
const parent = root.body || root.querySelector('div')
2023-07-03 00:03:29 +03:00
2023-08-12 12:34:02 +03:00
parent.style.overflow = 'hidden'
scrollbox.classList.add('h-full', 'overflow-y-auto')
2025-05-16 18:28:55 +03:00
scrollbox.parentNode.classList.add('h-screen', 'h-[100dvh]', 'overflow-y-auto')
2023-08-12 12:34:02 +03:00
scrollbox.parentNode.style.maxHeight = '-webkit-fill-available'
})
2023-07-03 00:03:29 +03:00
}
2023-09-05 01:35:48 +03:00
this.$nextTick(() => {
this.recalculateButtonDisabledKey = Math.random()
2023-09-10 12:55:41 +03:00
2024-07-02 20:27:25 +03:00
if (!this.dryRun) {
Promise.all([
this.maybeTrackEmailClick(),
this.maybeTrackSmsClick()
]).finally(() => {
this.trackViewForm()
})
}
2023-09-05 01:35:48 +03:00
})
2023-05-25 22:47:52 +03:00
},
methods: {
2024-01-26 16:45:32 +02:00
t (key) {
2024-02-15 22:13:14 +02:00
return this.i18n[key] || i18n[this.language?.toLowerCase()]?.[key] || i18n[this.browserLanguage]?.[key] || i18n.en[key] || key
2024-01-26 16:45:32 +02:00
},
2024-04-20 18:25:24 +03:00
onOrientationChange (event) {
this.orientation = event.target.type
},
2024-12-07 01:35:59 +02:00
checkFieldDocumentsConditions (field) {
if (field.areas?.length) {
return field.areas.some((area) => {
return this.attachmentConditionsIndex[area.attachment_uuid]
})
} else {
return true
}
},
2026-01-28 13:24:05 +02:00
checkFieldConditions (field, cache = {}) {
2026-02-05 11:56:22 +02:00
const cacheKey = field.uuid || field.attachment_uuid
2026-01-28 13:24:05 +02:00
2026-02-05 11:56:22 +02:00
if (cache[cacheKey] !== undefined) {
return cache[cacheKey]
}
2026-01-28 13:24:05 +02:00
2024-03-01 23:29:37 +02:00
if (field.conditions?.length) {
2024-11-27 21:47:53 +02:00
const result = field.conditions.reduce((acc, cond) => {
if (cond.operation === 'or') {
2026-01-28 13:24:05 +02:00
acc.push(acc.pop() || this.checkFieldCondition(cond, cache))
2024-11-27 21:47:53 +02:00
} else {
2026-01-28 13:24:05 +02:00
acc.push(this.checkFieldCondition(cond, cache))
2024-08-07 23:25:23 +03:00
}
2024-11-27 21:47:53 +02:00
return acc
}, [])
2024-03-01 23:29:37 +02:00
2026-02-05 11:56:22 +02:00
cache[cacheKey] = !result.includes(false)
} else {
cache[cacheKey] = true
2024-11-27 21:47:53 +02:00
}
2026-01-28 13:24:05 +02:00
2026-02-05 11:56:22 +02:00
return cache[cacheKey]
2024-11-27 21:47:53 +02:00
},
2026-01-28 13:24:05 +02:00
checkFieldCondition (condition, cache = {}) {
2024-11-27 21:47:53 +02:00
const field = this.fieldsUuidIndex[condition.field_uuid]
2024-03-01 23:29:37 +02:00
2026-01-31 08:39:32 +02:00
if (['not_empty', 'checked', 'equal', 'contains', 'greater_than', 'less_than'].includes(condition.action) && field && !this.checkFieldConditions(field, cache)) {
2024-11-27 21:47:53 +02:00
return false
}
2025-03-18 12:56:59 +02:00
const defaultValue = !field || isEmpty(field.default_value) ? null : field.default_value
2024-11-27 21:47:53 +02:00
if (['empty', 'unchecked'].includes(condition.action)) {
2025-03-18 12:56:59 +02:00
return isEmpty(this.values[condition.field_uuid] ?? defaultValue)
2024-11-27 21:47:53 +02:00
} else if (['not_empty', 'checked'].includes(condition.action)) {
2025-03-18 12:56:59 +02:00
return !isEmpty(this.values[condition.field_uuid] ?? defaultValue)
2026-01-31 08:39:32 +02:00
} else if (field?.type === 'number' && ['equal', 'not_equal', 'greater_than', 'less_than'].includes(condition.action)) {
const value = this.values[condition.field_uuid] ?? defaultValue
if (isEmpty(value) || isEmpty(condition.value)) return false
const actual = parseFloat(value)
const expected = parseFloat(condition.value)
if (Number.isNaN(actual) || Number.isNaN(expected)) return false
if (condition.action === 'equal') return Math.abs(actual - expected) < Number.EPSILON
if (condition.action === 'not_equal') return Math.abs(actual - expected) > Number.EPSILON
if (condition.action === 'greater_than') return actual > expected
if (condition.action === 'less_than') return actual < expected
return false
2024-11-27 21:47:53 +02:00
} else if (['equal', 'contains'].includes(condition.action) && field) {
if (field.options) {
const option = field.options.find((o) => o.uuid === condition.value)
2026-01-15 17:23:26 +02:00
if (option) {
const values = [this.values[condition.field_uuid] ?? defaultValue].flat()
return values.includes(this.optionValue(option, field.options.indexOf(option)))
} else {
return false
}
2024-11-27 21:47:53 +02:00
} else {
2025-03-18 12:56:59 +02:00
return [this.values[condition.field_uuid] ?? defaultValue].flat().includes(condition.value)
2024-11-27 21:47:53 +02:00
}
} else if (['not_equal', 'does_not_contain'].includes(condition.action) && field) {
2026-01-15 17:23:26 +02:00
if (field.options) {
const option = field.options.find((o) => o.uuid === condition.value)
2024-11-27 21:47:53 +02:00
2026-01-15 17:23:26 +02:00
if (option) {
const values = [this.values[condition.field_uuid] ?? defaultValue].flat()
return !values.includes(this.optionValue(option, field.options.indexOf(option)))
} else {
return false
}
} else {
return false
}
2024-03-01 23:29:37 +02:00
} else {
return true
}
},
optionValue (option, index) {
if (option.value) {
return option.value
} else {
return `${this.t('option')} ${index + 1}`
}
},
2026-02-04 10:51:11 +02:00
findNextStep (currentStepIndex) {
if (this.onlyRequiredFields) {
return this.stepFields.find((step, index) => index > currentStepIndex && step.some((f) => f.required))
} else {
return this.stepFields[currentStepIndex + 1]
}
},
2023-09-10 12:55:41 +03:00
maybeTrackEmailClick () {
2023-12-14 21:22:26 +02:00
const { queryParams } = this
2023-09-10 12:55:41 +03:00
if (queryParams.has('t')) {
2023-09-10 20:29:34 +03:00
const t = queryParams.get('t')
queryParams.delete('t')
const newUrl = [window.location.pathname, queryParams.toString()].filter(Boolean).join('?')
window.history.replaceState({}, document.title, newUrl)
return fetch(this.baseUrl + '/api/submitter_email_clicks', {
2023-09-10 12:55:41 +03:00
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
2023-09-10 20:29:34 +03:00
t,
2023-09-10 12:55:41 +03:00
submitter_slug: this.submitterSlug
})
})
2023-09-10 20:29:34 +03:00
} else {
return Promise.resolve({})
2023-09-10 12:55:41 +03:00
}
},
2023-09-27 23:28:33 +03:00
maybeTrackSmsClick () {
2023-12-14 21:22:26 +02:00
const { queryParams } = this
2023-09-27 23:28:33 +03:00
if (queryParams.has('c')) {
const c = queryParams.get('c')
queryParams.delete('c')
const newUrl = [window.location.pathname, queryParams.toString()].filter(Boolean).join('?')
window.history.replaceState({}, document.title, newUrl)
return fetch(this.baseUrl + '/api/submitter_sms_clicks', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
c,
submitter_slug: this.submitterSlug
})
})
} else {
return Promise.resolve({})
}
},
2023-09-10 12:55:41 +03:00
trackViewForm () {
fetch(this.baseUrl + '/api/submitter_form_views', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
submitter_slug: this.submitterSlug
})
})
},
2024-02-12 21:22:04 +02:00
previousSignatureValueFor (field) {
2024-04-25 17:51:36 +03:00
if (this.reuseSignature !== false) {
2026-01-30 09:58:30 +02:00
const signatureField = this.fields.findLast
? this.fields.findLast((f) => f.type === 'signature' && field.preferences?.format === f.preferences?.format && !!this.values[f.uuid])
: [...this.fields].reverse().find((f) => f.type === 'signature' && field.preferences?.format === f.preferences?.format && !!this.values[f.uuid])
2024-02-12 21:22:04 +02:00
2024-04-25 17:51:36 +03:00
return this.values[signatureField?.uuid]
} else {
return null
}
2024-02-12 21:22:04 +02:00
},
2024-08-07 23:18:03 +03:00
goToStep (stepIndex, scrollToArea = false, clickUpload = false) {
2026-07-16 15:55:21 +03:00
this.isInvite = false
2024-08-07 23:18:03 +03:00
this.currentStep = stepIndex
2023-10-15 21:41:47 +03:00
this.showFillAllRequiredFields = false
2023-05-25 22:47:52 +03:00
this.$nextTick(() => {
2023-09-05 01:35:48 +03:00
this.recalculateButtonDisabledKey = Math.random()
2024-05-30 00:35:35 +03:00
if (!this.isCompleted) {
if (scrollToArea) {
2025-03-20 18:38:38 +02:00
this.$nextTick(() => {
setTimeout(() => this.scrollIntoField(this.currentField), 1)
})
2024-05-30 00:35:35 +03:00
}
2023-06-15 01:05:04 +03:00
2024-06-27 17:41:08 +03:00
this.enableScrollIntoField = false
2026-04-16 12:41:42 +03:00
this.$refs.form.querySelector('input[type="date"], input[type="number"], input[type="text"], input[type="tel"], textarea, select')?.focus()
2024-06-27 17:41:08 +03:00
this.enableScrollIntoField = true
2024-05-30 00:35:35 +03:00
if (clickUpload && !this.values[this.currentField.uuid] && ['file', 'image'].includes(this.currentField.type)) {
this.$refs.form.querySelector('input[type="file"]')?.click()
}
2023-06-15 01:05:04 +03:00
}
2023-05-25 22:47:52 +03:00
})
},
2023-07-08 20:51:37 +03:00
saveStep (formData) {
2026-07-16 15:55:21 +03:00
if (!formData && !this.$refs.form) {
return
}
2024-02-23 19:17:25 +02:00
const currentFieldUuids = this.currentStepFields.map((f) => f.uuid)
2024-04-20 17:07:31 +03:00
const currentFieldType = this.currentField.type
2025-03-13 18:52:34 +02:00
if (!formData && !this.$refs.form.checkValidity() && currentFieldUuids.every((fieldUuid) => isEmpty(this.submittedValues[fieldUuid]) || !isEmpty(this.values[fieldUuid]))) {
2024-10-24 18:45:08 +03:00
return
}
2024-07-02 20:27:25 +03:00
if (this.dryRun) {
currentFieldUuids.forEach((fieldUuid) => {
this.submittedValues[fieldUuid] = this.values[fieldUuid]
})
return Promise.resolve({})
} else if (this.isCompleted) {
2023-06-27 00:57:29 +03:00
return Promise.resolve({})
} else {
2023-08-12 12:34:02 +03:00
return fetch(this.baseUrl + this.submitPath, {
2023-06-27 00:57:29 +03:00
method: 'POST',
2026-02-14 18:10:16 +02:00
body: formData || new FormData(this.$refs.form),
...this.fetchOptions
}).then((response) => {
if (response.status === 200) {
2024-02-23 19:17:25 +02:00
currentFieldUuids.forEach((fieldUuid) => {
this.submittedValues[fieldUuid] = this.values[fieldUuid]
2024-04-20 17:07:31 +03:00
if (currentFieldType === 'phone') {
this.phoneVerifiedValues[fieldUuid] = this.values[fieldUuid]
}
2024-02-23 19:17:25 +02:00
})
}
return response
2023-06-27 00:57:29 +03:00
})
}
2023-06-20 00:24:39 +03:00
},
2024-01-06 17:21:15 +02:00
scrollIntoField (field) {
2024-06-27 17:41:08 +03:00
if (this.enableScrollIntoField) {
return this.$refs.areas.scrollIntoField(field)
}
2024-01-06 17:21:15 +02:00
},
scrollIntoArea (area) {
return this.$refs.areas.scrollIntoArea(area)
},
2024-11-07 20:58:43 +02:00
async submitStep (e) {
2023-05-25 22:47:52 +03:00
this.isSubmitting = true
2024-11-08 22:12:07 +02:00
const forceComplete = e?.submitter?.getAttribute('name') === 'completed'
2024-11-07 20:58:43 +02:00
if (forceComplete) {
this.isSubmittingComplete = true
}
2026-02-04 10:51:11 +02:00
const submitStepIndex = this.currentStep
2024-10-11 20:17:50 +03:00
2026-01-02 16:07:04 +02:00
const stepPromise = ['signature', 'phone', 'initials', 'payment', 'verification', 'kba'].includes(this.currentField.type)
2023-05-25 22:47:52 +03:00
? this.$refs.currentStep.submit
: () => Promise.resolve({})
2023-09-06 22:21:15 +03:00
stepPromise().then(async () => {
2023-09-27 23:28:33 +03:00
const emptyRequiredField = this.stepFields.find((fields, index) => {
2026-02-04 10:51:11 +02:00
if (forceComplete ? index === submitStepIndex : index >= submitStepIndex) {
2024-02-23 19:17:25 +02:00
return false
}
return fields.some((f) => {
return f.required && (f.type === 'phone' || !this.allowToSkip) && isEmpty(this.submittedValues[f.uuid])
})
2023-09-27 23:28:33 +03:00
})
2023-09-05 01:00:21 +03:00
const formData = new FormData(this.$refs.form)
2026-02-04 10:51:11 +02:00
const isLastStep = (this.onlyRequiredFields ? !this.findNextStep(submitStepIndex) : (submitStepIndex === this.stepFields.length - 1)) || forceComplete
2023-09-05 01:00:21 +03:00
2024-12-19 17:17:34 +02:00
if (isLastStep && !emptyRequiredField && !this.inviteSubmitters.length && !this.optionalInviteSubmitters.length) {
2023-09-05 01:00:21 +03:00
formData.append('completed', 'true')
2025-06-13 19:12:35 +03:00
formData.append('timezone', Intl.DateTimeFormat().resolvedOptions().timeZone)
2023-09-05 01:00:21 +03:00
}
2023-05-25 22:47:52 +03:00
2024-04-20 17:07:31 +03:00
let saveStepRequest
2024-04-21 16:40:28 +03:00
if (!isLastStep && this.phoneVerifiedValues[this.currentField.uuid] && this.phoneVerifiedValues[this.currentField.uuid] === this.values[this.currentField.uuid]) {
2024-04-20 17:07:31 +03:00
saveStepRequest = Promise.resolve({})
} else {
saveStepRequest = this.saveStep(formData)
}
await saveStepRequest.then(async (response) => {
2023-12-14 21:22:26 +02:00
if (response.status === 422 || response.status === 500) {
2023-09-05 01:00:21 +03:00
const data = await response.json()
2023-07-08 20:51:37 +03:00
2025-03-28 21:36:26 +02:00
if (data.field_uuid) {
const field = this.fieldsUuidIndex[data.field_uuid]
2025-03-29 21:12:22 +02:00
if (field) {
const step = this.stepFields.findIndex((fields) => fields.includes(field))
2025-03-28 21:36:26 +02:00
2025-03-29 21:12:22 +02:00
if (step !== -1) {
this.goToStep(step, this.autoscrollFields)
this.showFillAllRequiredFields = true
}
}
return Promise.reject(new Error('Required field: ' + data.field_uuid))
2025-03-28 21:36:26 +02:00
} else if (data.error) {
2024-11-23 22:14:07 +02:00
const i18nKey = data.error.replace(/\s+/g, '_').toLowerCase()
2024-08-03 09:17:55 +03:00
2024-11-23 22:14:07 +02:00
alert(this.t(i18nKey) !== i18nKey ? this.t(i18nKey) : data.error)
} else {
alert(this.t('value_is_invalid'))
}
2023-07-08 20:51:37 +03:00
2023-09-05 01:00:21 +03:00
return Promise.reject(new Error(data.error))
}
2023-05-25 22:47:52 +03:00
2026-05-12 21:38:15 +03:00
this.isFormStarted = true
2026-02-04 10:51:11 +02:00
const nextStep = (isLastStep && emptyRequiredField) || (forceComplete ? null : this.findNextStep(submitStepIndex))
2023-09-05 01:00:21 +03:00
if (nextStep) {
2024-04-20 18:25:24 +03:00
if (this.alwaysMinimize) {
2024-09-20 23:53:33 +03:00
this.minimizeForm()
2024-04-20 18:25:24 +03:00
}
2024-08-07 23:18:03 +03:00
this.goToStep(this.stepFields.indexOf(nextStep), this.autoscrollFields)
2023-10-15 21:41:47 +03:00
if (emptyRequiredField === nextStep) {
this.showFillAllRequiredFields = true
}
2024-12-19 17:17:34 +02:00
} else if (this.inviteSubmitters.length || this.optionalInviteSubmitters.length) {
2024-09-12 23:15:10 +03:00
this.isInvite = true
2023-09-05 01:00:21 +03:00
} else {
2024-09-12 23:15:10 +03:00
this.performComplete(response)
2023-09-05 01:00:21 +03:00
}
}).catch(error => {
2023-12-19 15:45:30 +02:00
console.error(error)
2023-09-05 01:00:21 +03:00
}).finally(() => {
this.isSubmitting = false
2024-11-07 20:58:43 +02:00
this.isSubmittingComplete = false
2023-09-05 01:00:21 +03:00
})
2023-05-25 22:47:52 +03:00
}).catch(error => {
2025-03-29 13:40:25 +02:00
console.log(error)
2023-05-25 22:47:52 +03:00
}).finally(() => {
this.isSubmitting = false
2024-11-07 20:58:43 +02:00
this.isSubmittingComplete = false
2023-05-25 22:47:52 +03:00
})
2024-09-12 23:15:10 +03:00
},
2024-09-20 23:53:33 +03:00
minimizeForm () {
this.isFormVisible = false
this.isShowContinue = true
},
2024-09-12 23:15:10 +03:00
async performComplete (resp) {
this.isCompleted = true
2026-05-12 21:38:15 +03:00
this.isFormVisible = true
2024-09-12 23:15:10 +03:00
2024-09-23 01:25:43 +03:00
if (resp?.text) {
2024-09-12 23:15:10 +03:00
const respData = await resp.text()
if (respData) {
this.onComplete(JSON.parse(respData))
}
}
if (this.completedRedirectUrl) {
2025-08-20 21:22:59 +03:00
window.location.href = sanitizeUrl(this.completedRedirectUrl)
2026-04-16 12:41:42 +03:00
} else {
this.$nextTick(() => {
const root = this.$root.$el.parentNode.getRootNode()
const completedEl = root.getElementById('form_completed')
if (completedEl) {
completedEl.focus()
}
})
2024-09-12 23:15:10 +03:00
}
2023-05-25 22:47:52 +03:00
}
}
}
</script>