Skip to content

Commit

Permalink
Show hidden fieldtype in form submission
Browse files Browse the repository at this point in the history
  • Loading branch information
aerni committed Nov 1, 2024
1 parent 3bd3171 commit 4debb0d
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 5 deletions.
2 changes: 1 addition & 1 deletion resources/css/components/fieldtypes/hidden.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
HIDDEN FIELDTYPE
========================================================================== */

.hidden-fieldtype {
.hidden-fieldtype:not(.form-submission-field) {
display: none; /* So fancy */
}
22 changes: 20 additions & 2 deletions resources/js/components/fieldtypes/HiddenFieldtype.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
<template>
<input type="hidden" :name="name" :value="value" />
<div>
<text-input
v-if="this.isInsideFormSubmission"
type="text"
:name="name"
:value="value"
isReadOnly="true"
/>
<input
v-else
type="hidden"
:name="name"
:value="value"
/>
</div>
</template>

<script>
export default {
mixins: [Fieldtype]
mixins: [Fieldtype],
inject: {
isInsideFormSubmission: { default: false },
},
};
</script>
2 changes: 2 additions & 0 deletions resources/js/components/publish/Field.vue
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export default {
inject: {
storeName: { default: null },
isInsideConfigFields: { default: false },
isInsideFormSubmission: { default: false },
},
computed: {
Expand Down Expand Up @@ -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 }
Expand Down
11 changes: 9 additions & 2 deletions resources/js/components/publish/PublishForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
:name="name"
:blueprint="blueprint"
v-model="currentValues"
reference="collection"
:reference="initialReference"
:meta="meta"
:errors="errors"
v-slot="{ setFieldValue, setFieldMeta }"
Expand Down Expand Up @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions resources/views/forms/submission.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
:meta='@json($meta)'
:values='@json($values)'
read-only
initial-reference="{{ $reference }}"
></publish-form>

@endsection
5 changes: 5 additions & 0 deletions src/Forms/Submission.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public function show($form, $submission)
'values' => $fields->values(),
'meta' => $fields->meta(),
'title' => $submission->formattedDate(),
'reference' => $submission->reference(),
]);
}
}

0 comments on commit 4debb0d

Please sign in to comment.