Autofocus first field as settings option (#536)

Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
Chirag Chhatrala 2024-08-23 15:02:09 +05:30 committed by GitHub
parent 94b3d26672
commit a73badb091
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 36 additions and 1 deletions

View File

@ -62,6 +62,7 @@ abstract class UserFormRequest extends \Illuminate\Foundation\Http\FormRequest
'confetti_on_submission' => 'boolean',
'show_progress_bar' => 'boolean',
'auto_save' => 'boolean',
'auto_focus' => 'boolean',
// Properties
'properties' => 'required|array',

View File

@ -88,6 +88,7 @@ class Form extends Model implements CachableAttributes
'confetti_on_submission',
'show_progress_bar',
'auto_save',
'auto_focus',
// Security & Privacy
'can_be_indexed',

View File

@ -185,6 +185,11 @@
label="Auto save form response"
help="Will save data in browser, if user not submit the form then next time will auto prefill last entered data"
/>
<ToggleSwitchInput
name="auto_focus"
:form="form"
label="Auto focus first input on page"
/>
</editor-options-panel>
</template>

View File

@ -22,6 +22,7 @@ export const initForm = (defaultValue = {}, withDefaultProperties = false) => {
closed_text:
"This form has now been closed by its owner and does not accept submissions anymore.",
auto_save: true,
auto_focus: true,
border_radius: 'small',
size: 'md',

View File

@ -161,7 +161,7 @@ onMounted(() => {
console.error('Error appending custom code', e)
}
}
if (!isIframe) focusOnFirstFormElement()
if (!isIframe && form.value?.auto_focus) focusOnFirstFormElement()
}
}
})

View File

@ -0,0 +1,27 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class () extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('forms', function (Blueprint $table) {
$table->boolean('auto_focus')->default(true);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('forms', function (Blueprint $table) {
$table->dropColumn('auto_focus');
});
}
};