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

1245 lines
39 KiB
Vue
Raw Normal View History

2023-05-25 22:47:52 +03:00
<template>
<FieldAreas
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"
2024-01-24 23:20:53 +02:00
:with-label="!isAnonymousChecboxes && showFieldNames"
2023-06-16 00:04:05 +03:00
:current-step="currentStepFields"
2024-07-02 20:27:25 +03:00
:scroll-padding="scrollPadding"
@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
:steps="readonlyConditionalFields.map((e) => [e])"
:values="readonlyConditionalFields.reduce((acc, f) => { acc[f.uuid] = f.default_value; return acc }, {})"
:submitter="submitter"
:submittable="false"
/>
2024-02-24 01:01:36 +02:00
<FormulaFieldAreas
v-if="formulaFields.length"
:fields="formulaFields"
:values="values"
/>
2023-07-17 22:48:01 +03:00
<button
v-if="!isFormVisible"
2023-12-28 16:59:50 +02:00
id="expand_form_button"
2024-04-20 18:25:24 +03:00
class="btn btn-neutral flex text-white absolute bottom-0 w-full mb-3"
style="width: 96%; margin-left: 2%"
2024-02-24 17:34:22 +02:00
@click.prevent="[isFormVisible = true, 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"
/>
</button>
<div
2023-07-22 14:31:13 +03:00
v-show="isFormVisible"
2023-07-17 22:48:01 +03:00
id="form_container"
2024-01-03 18:12:35 +02:00
class="shadow-md bg-base-100 absolute bottom-0 w-full border-base-200 border p-4 rounded"
: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"
2023-07-17 22:48:01 +03:00
class="absolute right-0 mr-2 mt-2 top-0 hidden md:block"
2024-02-19 23:52:47 +02:00
:title="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"
/>
</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"
2023-07-17 22:48:01 +03:00
ref="form"
:action="submitPath"
method="post"
2024-02-15 00:58:47 +02:00
class="mx-auto"
: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"
>
<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"
2024-03-09 18:24:21 +02:00
class="label text-2xl"
:class="{ 'mb-2': !currentField.description }"
>
<MarkdownContent
v-if="currentField.title"
:string="currentField.title"
/>
<template v-else>
{{ currentField.name }}
<template v-if="!currentField.required">({{ t('optional') }})</template>
</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"
dir="auto"
class="mb-3 px-1"
>
<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"
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)"
2023-07-17 22:48:01 +03:00
:for="currentField.uuid"
2024-01-07 14:19:21 +02:00
dir="auto"
2024-03-09 18:24:21 +02:00
class="label text-2xl"
:class="{ 'mb-2': !currentField.description }"
>
<MarkdownContent
v-if="currentField.title"
:string="currentField.title"
/>
<template v-else>
{{ currentField.name }}
<template v-if="!currentField.required">({{ t('optional') }})</template>
</template>
2023-07-17 22:48:01 +03:00
</label>
2024-03-09 18:24:21 +02:00
<div
v-if="currentField.description"
dir="auto"
class="mb-3 px-1"
>
<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"
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"
2023-07-17 22:48:01 +03:00
class="flex items-center space-x-3"
>
<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"
dir="auto"
class="mb-3 px-1"
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"
class="flex items-center space-x-3"
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"
:oninvalid="`this.setCustomValidity('${t('please_check_the_box_to_continue')}')`"
:onchange="`this.setCustomValidity(validity.valueMissing ? '${t('please_check_the_box_to_continue')}' : '');`"
: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"
2024-06-11 18:19:21 +03:00
:previous-value="previousSignatureValueFor(currentField) || 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"
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"
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"
: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"
2024-07-31 22:56:18 +03:00
:values="values"
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
/>
2023-06-16 23:39:55 +03:00
</div>
2023-12-14 21:22:26 +02:00
<div
v-if="currentField.type !== 'payment' || submittedValues[currentField.uuid]"
2024-06-02 14:50:37 +03:00
:class="currentField.type === 'signature' ? 'mt-2' : 'mt-6 md:mt-8'"
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"
class="base-button w-full flex justify-center"
: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"
/>
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"
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"
: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"
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"
/>
2023-12-31 17:23:27 +02:00
<div
v-if="stepFields.length < 80"
class="flex justify-center"
>
<div class="flex items-center mt-4 mb-1 flex-wrap">
2023-07-17 22:48:01 +03:00
<a
v-for="(step, index) in stepFields"
:key="step[0].uuid"
href="#"
2023-12-31 17:23:27 +02:00
class="inline border border-base-300 h-3 w-3 rounded-full mx-1 mt-1"
2023-10-15 21:41:47 +03:00
:class="{ 'bg-base-300': index === currentStep, 'bg-base-content': (index < currentStep && stepFields[index].every((f) => !f.required || ![null, undefined, ''].includes(values[f.uuid]))) || isCompleted, 'bg-white': index > currentStep }"
2024-08-07 23:18:03 +03:00
@click.prevent="isCompleted ? '' : [saveStep(), goToStep(index, true)]"
2023-07-17 22:48:01 +03:00
/>
</div>
2023-06-15 01:05:04 +03:00
</div>
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'
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'
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'
2023-05-25 22:47:52 +03:00
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,
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-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: () => []
},
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-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
},
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
},
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
},
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: ''
},
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: ''
},
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: ''
},
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,
2023-09-27 23:28:33 +03:00
submittedValues: {},
2023-09-05 01:35:48 +03:00
recalculateButtonDisabledKey: ''
2023-05-25 22:47:52 +03:00
}
},
computed: {
2024-04-20 18:25:24 +03:00
isMobile () {
return /android|iphone|ipad/i.test(navigator.userAgent)
},
2024-09-21 11:07:59 +03:00
submitButtonText () {
if (this.alwaysMinimize) {
2024-05-12 12:08:18 +03:00
return this.t('submit')
2024-09-21 11:07:59 +03:00
} else if (this.stepFields.length === this.currentStep + 1) {
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) {
const initialsField = [...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 () {
2024-02-23 19:17:25 +02:00
return this.currentField.type === 'checkbox' && this.currentStepFields.every((e) => !e.name && !e.required) && this.currentStepFields.length > 4
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 () {
return this.fields.filter((f) => f.readonly && f.conditions?.length && this.checkFieldConditions(f))
},
2023-06-16 00:04:05 +03:00
stepFields () {
2023-10-12 00:06:33 +03:00
return this.fields.filter((f) => !f.readonly).reduce((acc, f) => {
2023-06-16 00:04:05 +03:00
const prevStep = acc[acc.length - 1]
2024-03-01 23:29:37 +02:00
if (this.checkFieldConditions(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 () {
2024-07-31 22:56:18 +03:00
return this.fields.filter((f) => f.preferences?.formula && f.type !== 'payment')
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-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])))
const lastFilledStepIndex = this.stepFields.indexOf([...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]
if (requiredEmptyStepIndex !== -1) {
indexesList.push(requiredEmptyStepIndex)
}
if (lastFilledStepIndex !== -1) {
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
}
2023-07-03 00:03:29 +03:00
if (/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')
scrollbox.parentNode.classList.add('h-screen', 'overflow-y-auto')
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-03-01 23:29:37 +02:00
checkFieldConditions (field) {
if (field.conditions?.length) {
return field.conditions.reduce((acc, c) => {
2024-08-07 23:25:23 +03:00
const field = this.fieldsUuidIndex[c.field_uuid]
2024-08-19 19:29:53 +03:00
if (['not_empty', 'checked', 'equal', 'contains'].includes(c.action) && field && !this.checkFieldConditions(field)) {
2024-08-07 23:25:23 +03:00
return false
}
2024-03-01 23:29:37 +02:00
if (['empty', 'unchecked'].includes(c.action)) {
return acc && isEmpty(this.values[c.field_uuid])
} else if (['not_empty', 'checked'].includes(c.action)) {
return acc && !isEmpty(this.values[c.field_uuid])
2024-09-04 00:29:38 +03:00
} else if (['equal', 'contains'].includes(c.action) && field) {
2024-03-01 23:29:37 +02:00
const option = field.options.find((o) => o.uuid === c.value)
const values = [this.values[c.field_uuid]].flat()
return acc && values.includes(this.optionValue(option, field.options.indexOf(option)))
2024-09-04 00:29:38 +03:00
} else if (['not_equal', 'does_not_contain'].includes(c.action) && field) {
2024-03-01 23:29:37 +02:00
const option = field.options.find((o) => o.uuid === c.value)
const values = [this.values[c.field_uuid]].flat()
return acc && !values.includes(this.optionValue(option, field.options.indexOf(option)))
} else {
return acc
}
}, true)
} else {
return true
}
},
optionValue (option, index) {
if (option.value) {
return option.value
} else {
return `${this.t('option')} ${index + 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) {
const signatureField = [...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) {
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) {
2024-08-07 23:18:03 +03:00
this.scrollIntoField(this.currentField)
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
this.$refs.form.querySelector('input[type="date"], input[type="number"], input[type="text"], select')?.focus()
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) {
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
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',
2023-07-08 20:51:37 +03:00
body: formData || new FormData(this.$refs.form)
}).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)
},
2023-05-25 22:47:52 +03:00
async submitStep () {
this.isSubmitting = true
2024-10-11 20:17:50 +03:00
const submitStep = this.currentStep
2023-12-14 21:22:26 +02:00
const stepPromise = ['signature', 'phone', 'initials', 'payment'].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) => {
2024-10-11 20:17:50 +03:00
if (index >= submitStep) {
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)
2024-10-11 20:17:50 +03:00
const isLastStep = submitStep === this.stepFields.length - 1
2023-09-05 01:00:21 +03:00
2024-09-12 17:31:37 +03:00
if (isLastStep && !emptyRequiredField && !this.inviteSubmitters.length) {
2023-09-05 01:00:21 +03:00
formData.append('completed', 'true')
}
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
2024-08-03 09:17:55 +03:00
const i18nError = data.error ? this.t(data.error.replace(/\s+/g, '_').toLowerCase()) : ''
alert(i18nError !== data.error ? i18nError : (data.error || 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
2024-10-11 20:17:50 +03:00
const nextStep = (isLastStep && emptyRequiredField) || this.stepFields[submitStep + 1]
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-09-12 23:15:10 +03:00
} else if (this.inviteSubmitters.length) {
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
})
2023-05-25 22:47:52 +03:00
}).catch(error => {
2024-03-10 19:55:45 +02:00
if (error?.message === 'Image too small') {
2024-09-23 15:22:07 +03:00
alert(this.t('signature_is_too_small_please_redraw'))
2024-03-10 19:55:45 +02:00
} else {
console.log(error)
}
2023-05-25 22:47:52 +03:00
}).finally(() => {
this.isSubmitting = false
})
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
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) {
window.location.href = this.completedRedirectUrl
}
2023-05-25 22:47:52 +03:00
}
}
}
</script>