From 957b5e2c22b8dea146553127cfedfbf33be78c3b Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Fri, 18 Oct 2024 16:41:43 -0400 Subject: [PATCH 1/4] wip --- .../extend/forms/fields/group.antlers.html | 17 ++++++++++++ .../extend/forms/fields/text.antlers.html | 3 ++- src/Tags/Concerns/RendersForms.php | 26 +++++++++++++++++-- 3 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 resources/views/extend/forms/fields/group.antlers.html diff --git a/resources/views/extend/forms/fields/group.antlers.html b/resources/views/extend/forms/fields/group.antlers.html new file mode 100644 index 0000000000..fa0b875411 --- /dev/null +++ b/resources/views/extend/forms/fields/group.antlers.html @@ -0,0 +1,17 @@ +
+ {{ fields }} + +
+ +
{{ field }}
+ {{ if error }} +

{{ error }}

+ {{ /if }} +
+ {{ /fields }} +
diff --git a/resources/views/extend/forms/fields/text.antlers.html b/resources/views/extend/forms/fields/text.antlers.html index 327eed416f..91fb7c87bb 100644 --- a/resources/views/extend/forms/fields/text.antlers.html +++ b/resources/views/extend/forms/fields/text.antlers.html @@ -1,6 +1,7 @@ + getBag($errorBag) : new MessageBag; @@ -142,13 +142,23 @@ protected function getRenderableField($field, $errorBag = 'default', $manipulate ->filter()->all(); $data = array_merge($configDefaults, $field->toArray(), [ + 'handle' => $field->handle(), + 'name' => $this->convertDottedHandleToInputName($field->handle()), 'instructions' => $field->instructions(), 'error' => $errors->first($field->handle()) ?: null, 'default' => $field->value() ?? $field->defaultValue(), - 'old' => old($field->handle()), + 'old' => old($field->handle()), // dotted as well? 'value' => $value, ], $field->fieldtype()->extraRenderableFieldData()); + if ($field->fieldtype()->handle() === 'group') { + $data['fields'] = collect($field->fieldtype()->fields()->all()) + ->map(fn ($child) => $child->setHandle($field->handle().'.'.$child->handle())) + ->map(fn ($child) => $this->getRenderableField($child, $errorBag, $manipulateDataCallback, $field->handle())) + ->values() + ->all(); + } + if ($manipulateDataCallback instanceof Closure) { $data = $manipulateDataCallback($data, $field); } @@ -158,6 +168,18 @@ protected function getRenderableField($field, $errorBag = 'default', $manipulate return $data; } + protected function convertDottedHandleToInputName($handle) + { + ray($handle)->purple(); + $parts = collect(explode('.', $handle)); + + $first = $parts->pull(0); + + return $first.$parts + ->map(fn ($part) => '['.$part.']') + ->join(''); + } + /** * Minify field html. * From e09ec8ed2cd773a6aff49379119c31b5d05806c6 Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Fri, 18 Oct 2024 17:06:45 -0400 Subject: [PATCH 2/4] =?UTF-8?q?Deciding=20against=20doc=20here.=20We=20don?= =?UTF-8?q?=E2=80=99t=20do=20it=20for=20any=20of=20the=20other=20fieldtype?= =?UTF-8?q?s.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/views/extend/forms/fields/group.antlers.html | 1 - 1 file changed, 1 deletion(-) diff --git a/resources/views/extend/forms/fields/group.antlers.html b/resources/views/extend/forms/fields/group.antlers.html index fa0b875411..22b33148da 100644 --- a/resources/views/extend/forms/fields/group.antlers.html +++ b/resources/views/extend/forms/fields/group.antlers.html @@ -1,6 +1,5 @@
{{ fields }} -