Skip to content

Commit 2420012

Browse files
madassdevJhumanJ
andauthored
feat: form progress bar (#334)
* feat: form progress bar * complete progress bar implementation * fix lint --------- Co-authored-by: Julien Nahum <julien@nahum.net>
1 parent 26ad93a commit 2420012

File tree

5 files changed

+63
-0
lines changed

5 files changed

+63
-0
lines changed

app/Http/Requests/UserFormRequest.php

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public function rules()
7272
'editable_submissions' => 'boolean|nullable',
7373
'editable_submissions_button_text' => 'string|min:1|max:50',
7474
'confetti_on_submission' => 'boolean',
75+
'show_progress_bar' => 'boolean',
7576
'auto_save' => 'boolean',
7677

7778
// Properties

app/Models/Forms/Form.php

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ class Form extends Model implements CachableAttributes
9292
'editable_submissions',
9393
'editable_submissions_button_text',
9494
'confetti_on_submission',
95+
'show_progress_bar',
9596
'auto_save',
9697

9798
// Security & Privacy

client/components/open/forms/OpenForm.vue

+27
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,24 @@
55
</p>
66
</div>
77
<form v-else-if="dataForm" @submit.prevent="">
8+
<template v-if='form.show_progress_bar'>
9+
<div v-if='isIframe' class='mb-4 p-2'>
10+
<div class='w-full h-2 bg-gray-200 dark:bg-gray-600 relative border rounded-full overflow-hidden'>
11+
<div class='h-full transition-all duration-300 rounded-r-full'
12+
:class="{ 'w-0': formProgress === 0 }"
13+
:style="{ width: formProgress + '%', background: form.color }"
14+
/>
15+
</div>
16+
</div>
17+
<div v-else class='fixed top-0 left-0 right-0 z-50'>
18+
<div class='w-full h-[0.2rem] bg-gray-200 dark:bg-gray-600 relative overflow-hidden'>
19+
<div class='h-full transition-all duration-300'
20+
:class="{ 'w-0': formProgress === 0 }"
21+
:style="{ width: formProgress + '%', background: form.color }"
22+
/>
23+
</div>
24+
</div>
25+
</template>
826
<transition name="fade" mode="out-in">
927
<div :key="currentFieldGroupIndex" class="form-group flex flex-wrap w-full">
1028
<draggable v-model="currentFields"
@@ -147,6 +165,15 @@ export default {
147165
groups.push(currentGroup)
148166
return groups
149167
},
168+
formProgress () {
169+
const requiredFields = this.fields.filter(field => field.required)
170+
if (requiredFields.length === 0) {
171+
return 100
172+
}
173+
const completedFields = requiredFields.filter(field => ![null, undefined, ''].includes(this.dataFormValue[field.id]))
174+
const progress = (completedFields.length / requiredFields.length) * 100
175+
return Math.round(progress)
176+
},
150177
currentFields: {
151178
get () {
152179
return this.fieldGroups[this.currentFieldGroupIndex]

client/components/open/forms/components/form-components/FormCustomization.vue

+3
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@
5959
<pro-tag class="ml-1" />
6060
</template>
6161
</toggle-switch-input>
62+
<toggle-switch-input name="show_progress_bar" :form="form" class="mt-4"
63+
label="Show progress bar"
64+
/>
6265
<toggle-switch-input name="uppercase_labels" :form="form" class="mt-4"
6366
label="Uppercase Input Labels"
6467
/>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class () extends Migration {
8+
/**
9+
* Run the migrations.
10+
*
11+
* @return void
12+
*/
13+
public function up()
14+
{
15+
Schema::table('forms', function (Blueprint $table) {
16+
$table->boolean('show_progress_bar')->default(false);
17+
});
18+
}
19+
20+
/**
21+
* Reverse the migrations.
22+
*
23+
* @return void
24+
*/
25+
public function down()
26+
{
27+
Schema::table('forms', function (Blueprint $table) {
28+
$table->dropColumn('show_progress_bar');
29+
});
30+
}
31+
};

0 commit comments

Comments
 (0)