allow to make form field optional

pull/105/head
Alex Turchyn 2 years ago
parent 24380784a0
commit 4094bb03b7

@ -28,6 +28,9 @@
<template v-if="field.type === 'checkbox'"> <template v-if="field.type === 'checkbox'">
{{ fieldIndex + 1 }} {{ fieldIndex + 1 }}
</template> </template>
<template v-else-if="!field.required">
(optional)
</template>
</div> </div>
<div <div
v-if="isActive" v-if="isActive"

@ -22,7 +22,7 @@
:values="values" :values="values"
:attachments-index="attachmentsIndex" :attachments-index="attachmentsIndex"
:current-step="currentStepFields" :current-step="currentStepFields"
@focus-step="goToStep($event, false, true)" @focus-step="[saveStep(), goToStep($event, false, true)]"
/> />
<div> <div>
<form <form
@ -55,14 +55,16 @@
v-if="currentField.name" v-if="currentField.name"
:for="currentField.uuid" :for="currentField.uuid"
class="label text-2xl mb-2" class="label text-2xl mb-2"
>{{ currentField.name }}</label> >{{ currentField.name }}
<template v-if="!currentField.required">(optional)</template>
</label>
<div> <div>
<input <input
:id="currentField.uuid" :id="currentField.uuid"
v-model="values[currentField.uuid]" v-model="values[currentField.uuid]"
class="base-input !text-2xl w-full" class="base-input !text-2xl w-full"
:required="currentField.required" :required="currentField.required"
placeholder="Type here..." :placeholder="`Type here...${currentField.required ? '' : ' (optional)'}`"
type="text" type="text"
:name="`values[${currentField.uuid}]`" :name="`values[${currentField.uuid}]`"
@focus="$refs.areas.scrollIntoField(currentField)" @focus="$refs.areas.scrollIntoField(currentField)"
@ -74,7 +76,9 @@
v-if="currentField.name" v-if="currentField.name"
:for="currentField.uuid" :for="currentField.uuid"
class="label text-2xl mb-2" class="label text-2xl mb-2"
>{{ currentField.name }}</label> >{{ currentField.name }}
<template v-if="!currentField.required">(optional)</template>
</label>
<div class="text-center"> <div class="text-center">
<input <input
:id="currentField.uuid" :id="currentField.uuid"
@ -92,10 +96,12 @@
v-if="currentField.name" v-if="currentField.name"
:for="currentField.uuid" :for="currentField.uuid"
class="label text-2xl mb-2" class="label text-2xl mb-2"
>{{ currentField.name }}</label> >{{ currentField.name }}
<template v-if="!currentField.required">(optional)</template>
</label>
<select <select
:id="currentField.uuid" :id="currentField.uuid"
:required="true" :required="currentField.required"
class="select base-input !text-2xl w-full text-center font-normal" class="select base-input !text-2xl w-full text-center font-normal"
:name="`values[${currentField.uuid}]`" :name="`values[${currentField.uuid}]`"
@change="values[currentField.uuid] = $event.target.value" @change="values[currentField.uuid] = $event.target.value"
@ -122,7 +128,9 @@
v-if="currentField.name" v-if="currentField.name"
:for="currentField.uuid" :for="currentField.uuid"
class="label text-2xl mb-2" class="label text-2xl mb-2"
>{{ currentField.name }}</label> >{{ currentField.name }}
<template v-if="!currentField.required">(optional)</template>
</label>
<div class="flex w-full"> <div class="flex w-full">
<div class="space-y-3.5 mx-auto"> <div class="space-y-3.5 mx-auto">
<div <div
@ -140,7 +148,7 @@
class="base-radio !h-7 !w-7" class="base-radio !h-7 !w-7"
:name="`values[${currentField.uuid}]`" :name="`values[${currentField.uuid}]`"
:value="option" :value="option"
required :required="currentField.required"
> >
<span class="text-xl"> <span class="text-xl">
{{ option }} {{ option }}
@ -185,7 +193,7 @@
type="checkbox" type="checkbox"
class="base-checkbox !h-7 !w-7" class="base-checkbox !h-7 !w-7"
:checked="!!values[field.uuid]" :checked="!!values[field.uuid]"
@click="values[field.uuid] = !values[field.uuid]" @click="[$refs.areas.scrollIntoField(field), values[field.uuid] = !values[field.uuid]]"
> >
<span class="text-xl"> <span class="text-xl">
{{ currentField.name || currentField.type + ' ' + (index + 1) }} {{ currentField.name || currentField.type + ' ' + (index + 1) }}
@ -223,14 +231,23 @@
<div class="mt-8"> <div class="mt-8">
<button <button
type="submit" type="submit"
class="base-button w-full" class="base-button w-full flex justify-center"
:disabled="isSubmitting" :disabled="isSubmitting"
> >
<span v-if="isSubmitting"> <span class="flex">
Submitting... <IconInnerShadowTop
</span> v-if="isSubmitting"
<span v-else> class="mr-1 animate-spin"
Submit />
<span v-if="stepFields.length === currentStep + 1">
Submit
</span>
<span v-else>
Next
</span><span
v-if="isSubmitting"
class="w-6 flex justify-start mr-1"
><span>...</span></span>
</span> </span>
</button> </button>
</div> </div>
@ -262,6 +279,7 @@ import SignatureStep from './signature_step'
import AttachmentStep from './attachment_step' import AttachmentStep from './attachment_step'
import MultiSelectStep from './multi_select_step' import MultiSelectStep from './multi_select_step'
import FormCompleted from './completed' import FormCompleted from './completed'
import { IconInnerShadowTop } from '@tabler/icons-vue'
export default { export default {
name: 'SubmissionForm', name: 'SubmissionForm',
@ -272,6 +290,7 @@ export default {
SignatureStep, SignatureStep,
AttachmentStep, AttachmentStep,
MultiSelectStep, MultiSelectStep,
IconInnerShadowTop,
FormCompleted FormCompleted
}, },
props: { props: {
@ -369,6 +388,12 @@ export default {
} }
}) })
}, },
saveStep () {
return fetch(this.submitPath, {
method: 'POST',
body: new FormData(this.$refs.form)
})
},
async submitStep () { async submitStep () {
this.isSubmitting = true this.isSubmitting = true

@ -44,8 +44,28 @@
@focus="onNameFocus" @focus="onNameFocus"
@blur="onNameBlur" @blur="onNameBlur"
>{{ field.name || defaultName }}</span> >{{ field.name || defaultName }}</span>
<div
v-if="isNameFocus"
class="flex items-center ml-1.5"
>
<input
:id="`required-checkbox-${field.uuid}`"
v-model="field.required"
type="checkbox"
class="checkbox checkbox-xs no-animation rounded"
@mousedown.prevent
>
<label
:for="`required-checkbox-${field.uuid}`"
class="label text-xs"
@click.prevent="field.required = !field.required"
@mousedown.prevent
>Required</label>
</div>
<button <button
v-else
class="pr-1" class="pr-1"
title="Remove"
@click.prevent="$emit('remove')" @click.prevent="$emit('remove')"
> >
<IconX width="14" /> <IconX width="14" />

@ -321,6 +321,11 @@ export default {
w: area.maskW / 5 / area.maskW, w: area.maskW / 5 / area.maskW,
h: (area.maskW / 5 / area.maskW) * (area.maskW / area.maskH) h: (area.maskW / 5 / area.maskW) * (area.maskW / area.maskH)
} }
} else if (this.dragFieldType === 'signature') {
baseArea = {
w: area.maskW / 5 / area.maskW,
h: (area.maskW / 5 / area.maskW) * (area.maskW / area.maskH) / 2
}
} else { } else {
baseArea = { baseArea = {
w: area.maskW / 5 / area.maskW, w: area.maskW / 5 / area.maskW,

@ -9,21 +9,28 @@
style="min-width: 2px" style="min-width: 2px"
:class="iconInline ? 'inline' : 'block'" :class="iconInline ? 'inline' : 'block'"
class="peer outline-none focus:block" class="peer outline-none focus:block"
@keydown.enter.prevent="onEnter" @keydown.enter.prevent="blurContenteditable"
@focus="$emit('focus', $event)" @focus="$emit('focus', $event)"
@blur="onBlur" @blur="onBlur"
> >
{{ value }} {{ value }}
</span> </span>
<span
v-if="withRequired"
title="Required"
class="text-red-500 peer-focus:hidden"
@click="focusContenteditable"
>
*
</span>
<IconPencil <IconPencil
contenteditable="false" class="cursor-pointer flex-none opacity-0 group-hover/contenteditable:opacity-100 align-middle peer-focus:hidden"
class="cursor-pointer ml-1 flex-none opacity-0 group-hover/contenteditable:opacity-100 align-middle peer-focus:hidden"
:style="iconInline ? {} : { right: -(1.1 * iconWidth) + 'px' }" :style="iconInline ? {} : { right: -(1.1 * iconWidth) + 'px' }"
title="Edit" title="Edit"
:class="{ 'absolute': !iconInline, 'inline align-bottom': iconInline }" :class="{ 'ml-1': !withRequired, 'absolute': !iconInline, 'inline align-bottom': iconInline }"
:width="iconWidth" :width="iconWidth"
:stroke-width="iconStrokeWidth" :stroke-width="iconStrokeWidth"
@click="onPencilClick" @click="focusContenteditable"
/> />
</div> </div>
</template> </template>
@ -52,6 +59,11 @@ export default {
required: false, required: false,
default: 30 default: 30
}, },
withRequired: {
type: Boolean,
required: false,
default: false
},
iconStrokeWidth: { iconStrokeWidth: {
type: Number, type: Number,
required: false, required: false,
@ -79,10 +91,10 @@ export default {
this.$emit('update:model-value', this.value) this.$emit('update:model-value', this.value)
this.$emit('blur', e) this.$emit('blur', e)
}, },
onPencilClick () { focusContenteditable () {
this.$refs.contenteditable.focus() this.$refs.contenteditable.focus()
}, },
onEnter () { blurContenteditable () {
this.$refs.contenteditable.blur() this.$refs.contenteditable.blur()
} }
} }

@ -27,7 +27,28 @@
@blur="onNameBlur" @blur="onNameBlur"
/> />
</div> </div>
<div class="flex items-center space-x-1"> <div
v-if="isNameFocus"
class="flex items-center relative"
>
<input
:id="`required-checkbox-${field.uuid}`"
v-model="field.required"
type="checkbox"
class="checkbox checkbox-xs no-animation rounded"
@mousedown.prevent
>
<label
:for="`required-checkbox-${field.uuid}`"
class="label text-xs"
@click.prevent="field.required = !field.required"
@mousedown.prevent
>Required</label>
</div>
<div
v-else
class="flex items-center space-x-1"
>
<span <span
v-if="field.areas?.length" v-if="field.areas?.length"
class="dropdown dropdown-end" class="dropdown dropdown-end"
@ -178,6 +199,11 @@ export default {
} }
}, },
emits: ['set-draw', 'remove', 'move-up', 'move-down', 'scroll-to'], emits: ['set-draw', 'remove', 'move-up', 'move-down', 'scroll-to'],
data () {
return {
isNameFocus: false
}
},
computed: { computed: {
defaultName () { defaultName () {
const typeIndex = this.template.fields.filter((f) => f.type === this.field.type).indexOf(this.field) const typeIndex = this.template.fields.filter((f) => f.type === this.field.type).indexOf(this.field)
@ -192,6 +218,8 @@ export default {
}, },
methods: { methods: {
onNameFocus (e) { onNameFocus (e) {
this.isNameFocus = true
if (!this.field.name) { if (!this.field.name) {
setTimeout(() => { setTimeout(() => {
this.$refs.name.$refs.contenteditable.innerText = ' ' this.$refs.name.$refs.contenteditable.innerText = ' '
@ -220,6 +248,8 @@ export default {
this.field.name = '' this.field.name = ''
this.$refs.name.$refs.contenteditable.innerText = this.defaultName this.$refs.name.$refs.contenteditable.innerText = this.defaultName
} }
this.isNameFocus = false
}, },
removeArea (area) { removeArea (area) {
this.field.areas.splice(this.field.areas.indexOf(area), 1) this.field.areas.splice(this.field.areas.indexOf(area), 1)

@ -2,7 +2,7 @@
<span class="dropdown"> <span class="dropdown">
<label <label
tabindex="0" tabindex="0"
title="Type" :title="$t(modelValue)"
class="cursor-pointer" class="cursor-pointer"
> >
<component <component

@ -1,5 +1,5 @@
<!DOCTYPE html> <!DOCTYPE html>
<html data-theme="docuseal" class="h-full"> <html data-theme="docuseal">
<head> <head>
<title> <title>
Docuseal Docuseal
@ -11,7 +11,7 @@
<%= stylesheet_pack_tag 'application', media: 'all' %> <%= stylesheet_pack_tag 'application', media: 'all' %>
<%= yield :head %> <%= yield :head %>
</head> </head>
<body class="h-full"> <body>
<turbo-frame id="modal"></turbo-frame> <turbo-frame id="modal"></turbo-frame>
<%= render 'shared/navbar' %> <%= render 'shared/navbar' %>
<% if flash.present? %> <% if flash.present? %>

@ -1,5 +1,5 @@
<!DOCTYPE html> <!DOCTYPE html>
<html data-theme="docuseal" class="h-full"> <html data-theme="docuseal">
<head> <head>
<title> <title>
Docuseal Docuseal
@ -11,7 +11,7 @@
<%= stylesheet_pack_tag 'form', media: 'all' %> <%= stylesheet_pack_tag 'form', media: 'all' %>
<%= yield :head %> <%= yield :head %>
</head> </head>
<body class="h-full"> <body>
<%= yield %> <%= yield %>
</body> </body>
</html> </html>

@ -2,12 +2,12 @@
<div class="space-y-6 mx-auto"> <div class="space-y-6 mx-auto">
<div class="space-y-6"> <div class="space-y-6">
<div class="flex items-center justify-center"> <div class="flex items-center justify-center">
<div class="flex items-center"> <a href="/" class="flex items-center">
<div class="mr-3"> <div class="mr-3">
<%= render 'shared/logo', width: "50px", height: "50px"%> <%= render 'shared/logo', width: "50px", height: "50px"%>
</div> </div>
<h1 class="text-5xl font-bold text-center">DocuSeal</h1> <h1 class="text-5xl font-bold text-center">DocuSeal</h1>
</div> </a>
</div> </div>
<div class="flex items-center bg-base-300 rounded-xl p-4 mb-4"> <div class="flex items-center bg-base-300 rounded-xl p-4 mb-4">
<div class="flex items-center"> <div class="flex items-center">

@ -1,7 +1,7 @@
<% attachment_field_uuids = @submitter.submission.template.fields.select { |f| f['type'].in?(%w[image signature file]) }.pluck('uuid') %> <% attachment_field_uuids = @submitter.submission.template.fields.select { |f| f['type'].in?(%w[image signature file]) }.pluck('uuid') %>
<% values = @submitter.submission.submitters.reduce({}) { |acc, e| acc.merge(e.values) } %> <% values = @submitter.submission.submitters.reduce({}) { |acc, e| acc.merge(e.values) } %>
<% attachments = ActiveStorage::Attachment.where(uuid: values.values_at(*attachment_field_uuids).flatten).preload(:blob) %> <% attachments = ActiveStorage::Attachment.where(uuid: values.values_at(*attachment_field_uuids).flatten).preload(:blob) %>
<div class="mx-auto block pb-72 select-none" style="max-width: 1000px"> <div class="mx-auto block pb-72" style="max-width: 1000px">
<div class="mt-4 flex"> <div class="mt-4 flex">
<a href="<%= root_path %>" class="mx-auto text-2xl md:text-3xl font-bold items-center flex space-x-3"> <a href="<%= root_path %>" class="mx-auto text-2xl md:text-3xl font-bold items-center flex space-x-3">
<%= render 'shared/logo', class: 'w-9 h-9 md:w-12 md:h-12' %> <%= render 'shared/logo', class: 'w-9 h-9 md:w-12 md:h-12' %>

@ -34,7 +34,7 @@ Rails.application.routes.draw do
resources :submissions, only: %i[index new create] resources :submissions, only: %i[index new create]
end end
resources :start_form, only: %i[show update], path: 't', param: 'slug' do resources :start_form, only: %i[show update], path: 'd', param: 'slug' do
get :completed get :completed
end end

Loading…
Cancel
Save