From 4debb0d844e25ee5f20632dc66266773588b5ed8 Mon Sep 17 00:00:00 2001 From: Michael Aerni Date: Fri, 1 Nov 2024 12:38:24 -0400 Subject: [PATCH] Show hidden fieldtype in form submission --- .../css/components/fieldtypes/hidden.css | 2 +- .../components/fieldtypes/HiddenFieldtype.vue | 22 +++++++++++++++++-- resources/js/components/publish/Field.vue | 2 ++ .../js/components/publish/PublishForm.vue | 11 ++++++++-- resources/views/forms/submission.blade.php | 1 + src/Forms/Submission.php | 5 +++++ .../CP/Forms/FormSubmissionsController.php | 1 + 7 files changed, 39 insertions(+), 5 deletions(-) diff --git a/resources/css/components/fieldtypes/hidden.css b/resources/css/components/fieldtypes/hidden.css index 599977a070..8db3f1c709 100644 --- a/resources/css/components/fieldtypes/hidden.css +++ b/resources/css/components/fieldtypes/hidden.css @@ -2,6 +2,6 @@ HIDDEN FIELDTYPE ========================================================================== */ -.hidden-fieldtype { +.hidden-fieldtype:not(.form-submission-field) { display: none; /* So fancy */ } diff --git a/resources/js/components/fieldtypes/HiddenFieldtype.vue b/resources/js/components/fieldtypes/HiddenFieldtype.vue index 1c55426a4f..23fb460d22 100644 --- a/resources/js/components/fieldtypes/HiddenFieldtype.vue +++ b/resources/js/components/fieldtypes/HiddenFieldtype.vue @@ -1,9 +1,27 @@ diff --git a/resources/js/components/publish/Field.vue b/resources/js/components/publish/Field.vue index 2492e6c978..b2f71abbd9 100644 --- a/resources/js/components/publish/Field.vue +++ b/resources/js/components/publish/Field.vue @@ -112,6 +112,7 @@ export default { inject: { storeName: { default: null }, isInsideConfigFields: { default: false }, + isInsideFormSubmission: { default: false }, }, computed: { @@ -159,6 +160,7 @@ export default { `${this.config.component || this.config.type}-fieldtype`,, this.isReadOnly ? 'read-only-field' : '', this.isInsideConfigFields ? 'config-field' : `${tailwind_width_class(this.config.width)}`, + this.isInsideFormSubmission ? 'form-submission-field' : '', this.config.classes || '', this.config.full_width_setting ? 'full-width-setting' : '', { 'has-error': this.hasError || this.hasNestedError } diff --git a/resources/js/components/publish/PublishForm.vue b/resources/js/components/publish/PublishForm.vue index e1ff1f2f80..e58e7dc46b 100644 --- a/resources/js/components/publish/PublishForm.vue +++ b/resources/js/components/publish/PublishForm.vue @@ -5,7 +5,7 @@ :name="name" :blueprint="blueprint" v-model="currentValues" - reference="collection" + :reference="initialReference" :meta="meta" :errors="errors" v-slot="{ setFieldValue, setFieldMeta }" @@ -40,7 +40,14 @@ export default { breadcrumbs: Array, action: String, method: { type: String, default: 'post' }, - readOnly: { type: Boolean, default: false } + readOnly: { type: Boolean, default: false }, + initialReference: { type: String, default: 'collection' }, + }, + + provide() { + return { + isInsideFormSubmission: this.initialReference.startsWith('submission::'), + } }, data() { diff --git a/resources/views/forms/submission.blade.php b/resources/views/forms/submission.blade.php index ead3218ca0..4f5e9354bf 100644 --- a/resources/views/forms/submission.blade.php +++ b/resources/views/forms/submission.blade.php @@ -14,6 +14,7 @@ :meta='@json($meta)' :values='@json($values)' read-only + initial-reference="{{ $reference }}" > @endsection diff --git a/src/Forms/Submission.php b/src/Forms/Submission.php index c279bef08a..3f89ec7658 100644 --- a/src/Forms/Submission.php +++ b/src/Forms/Submission.php @@ -268,6 +268,11 @@ public function fileData() return $this->data()->all(); } + public function reference() + { + return "submission::{$this->id()}"; + } + public function __get($key) { return $this->get($key); diff --git a/src/Http/Controllers/CP/Forms/FormSubmissionsController.php b/src/Http/Controllers/CP/Forms/FormSubmissionsController.php index 2940c8f7ed..25426faa5a 100644 --- a/src/Http/Controllers/CP/Forms/FormSubmissionsController.php +++ b/src/Http/Controllers/CP/Forms/FormSubmissionsController.php @@ -91,6 +91,7 @@ public function show($form, $submission) 'values' => $fields->values(), 'meta' => $fields->meta(), 'title' => $submission->formattedDate(), + 'reference' => $submission->reference(), ]); } }