diff --git a/resources/views/extend/forms/fields.antlers.html b/resources/views/extend/forms/fields.antlers.html index 140c41c90a..519bc79910 100644 --- a/resources/views/extend/forms/fields.antlers.html +++ b/resources/views/extend/forms/fields.antlers.html @@ -6,8 +6,11 @@ * {{ /if }} -
{{ instructions }}
+ {{ /if }} +{{ instructions }}
{{ /if }} {{ if error }} diff --git a/src/Forms/FieldsVariable.php b/src/Forms/FieldsVariable.php new file mode 100644 index 0000000000..542333370d --- /dev/null +++ b/src/Forms/FieldsVariable.php @@ -0,0 +1,21 @@ + $fields])->render(), + $fields + ); + } + + public function toArray() + { + return $this->extra; + } +} diff --git a/src/Forms/Tags.php b/src/Forms/Tags.php index f44018e7c6..8a7d816043 100644 --- a/src/Forms/Tags.php +++ b/src/Forms/Tags.php @@ -74,7 +74,7 @@ public function create() $data['sections'] = $this->getSections($this->sessionHandle(), $jsDriver); - $data['fields'] = collect($data['sections'])->flatMap->fields->all(); + $data['fields'] = new FieldsVariable(collect($data['sections'])->flatMap->fields->all()); $data['honeypot'] = $form->honeypot(); diff --git a/tests/Tags/Form/FormCreateTest.php b/tests/Tags/Form/FormCreateTest.php index 3be2cc95ad..cbbd668037 100644 --- a/tests/Tags/Form/FormCreateTest.php +++ b/tests/Tags/Form/FormCreateTest.php @@ -5,10 +5,13 @@ use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Storage; +use Illuminate\Testing\Assert as PHPUnit; +use Illuminate\Testing\Constraints\SeeInOrder; use Illuminate\Validation\ValidationException; use PHPUnit\Framework\Attributes\Test; use Statamic\Facades\AssetContainer; use Statamic\Facades\Form; +use Statamic\Forms\FieldsVariable; use Statamic\Statamic; class FormCreateTest extends FormTestCase @@ -74,6 +77,26 @@ public function it_dynamically_renders_fields_array() $this->assertEquals(['Full Name', 'Email Address', 'Message'], $fieldOrder[1]); } + #[Test] + public function it_dynamically_renders_fields_view_using_single_tag() + { + $output = $this->normalizeHtml($this->tag(<<<'EOT' +{{ form:contact }} + {{ fields }} +{{ /form:contact }} +EOT + )); + + PHPUnit::assertThat([ + '', + '', + '', + '', + '', + '', + ], new SeeInOrder($output)); + } + #[Test] public function it_dynamically_renders_with_form_handle() { @@ -504,20 +527,20 @@ public function it_dynamically_renders_sections_array() $output = $this->normalizeHtml($this->tag(<<<'EOT' {{ form:survey }} {{ sections }} -