diff --git a/src/Tags/Concerns/RendersForms.php b/src/Tags/Concerns/RendersForms.php
index f7809e616f..67cffd56fd 100644
--- a/src/Tags/Concerns/RendersForms.php
+++ b/src/Tags/Concerns/RendersForms.php
@@ -3,9 +3,11 @@
namespace Statamic\Tags\Concerns;
use Closure;
+use Illuminate\Support\HtmlString;
use Illuminate\Support\MessageBag;
use Statamic\Fields\Field;
use Statamic\Forms\RenderableField;
+use Statamic\Support\Arr;
use Statamic\Support\Str;
trait RendersForms
@@ -167,6 +169,10 @@ protected function getRenderableField($field, $errorBag = 'default', $manipulate
$data = $manipulateDataCallback($data, $field);
}
+ if ($showField = Arr::get($data, 'show_field')) {
+ $data['show_field'] = new HtmlString($showField);
+ }
+
$data['field'] = new RenderableField($field, $data);
return $data;
diff --git a/tests/Tags/Form/FormCreateAlpineTest.php b/tests/Tags/Form/FormCreateAlpineTest.php
index 194433698a..11d12bce63 100644
--- a/tests/Tags/Form/FormCreateAlpineTest.php
+++ b/tests/Tags/Form/FormCreateAlpineTest.php
@@ -809,6 +809,35 @@ public function it_merges_any_x_data_passed_to_the_tag()
$this->assertStringContainsString($expected, $output);
}
+ #[Test]
+ public function it_properly_escapes_show_field_js_in_blade()
+ {
+ $output = $this->blade(<<<'EOT'
+
+
+
+
+
+ @if ($field['handle'] === 'message')
+
+ @endif
+
+
+EOT
+ );
+
+ preg_match_all('/<\/template>/U', $output, $js);
+
+ $expected = [
+ 'Statamic.$conditions.showField('.$this->jsonEncode(['if' => ['email' => 'not empty']]).', $data, \'message\')',
+ 'Statamic.$conditions.showField('.$this->jsonEncode(['if' => ['name' => 'not empty']]).', $data, \'my_favourites\')',
+ 'Statamic.$conditions.showField('.$this->jsonEncode(['if' => ['$root.likes_animals' => 'is true']]).', $data, \'my_favourites.favourite_animals\')',
+ 'Statamic.$conditions.showField('.$this->jsonEncode(['if' => ['email' => 'not empty']]).', $data, \'message\')',
+ ];
+
+ $this->assertSame($expected, $js[1]);
+ }
+
private function jsonEncode($data)
{
return Statamic::modify($data)->toJson()->entities();
diff --git a/tests/Tags/Form/FormCreateCustomDriverTest.php b/tests/Tags/Form/FormCreateCustomDriverTest.php
index b652ae7ea6..969b015da9 100644
--- a/tests/Tags/Form/FormCreateCustomDriverTest.php
+++ b/tests/Tags/Form/FormCreateCustomDriverTest.php
@@ -57,9 +57,9 @@ public function custom_driver_can_add_to_renderable_field_data()
{
$output = $this->tag(<<<'EOT'
{{ form:contact js="custom_driver" }}
- {{ fields }}
+ {{ form:fields }}
- {{ /fields }}
+ {{ /form:fields }}
{{ /form:contact }}
EOT
);
@@ -74,9 +74,9 @@ public function custom_driver_can_add_to_renderable_field_attributes()
{
$output = $this->normalizeHtml($this->tag(<<<'EOT'
{{ form:contact js="custom_driver" }}
- {{ fields }}
+ {{ form:fields }}
{{ field }}
- {{ /fields }}
+ {{ /form:fields }}
{{ /form:contact }}
EOT
));
@@ -100,9 +100,9 @@ public function custom_driver_get_show_field_js_in_dynamic_fields_array()
{
$output = $this->tag(<<<'EOT'
{{ form:contact js="custom_driver" }}
- {{ fields }}
+ {{ form:fields }}
- {{ /fields }}
+ {{ /form:fields }}
{{ /form:contact }}
EOT
);
diff --git a/tests/Tags/Form/FormTestCase.php b/tests/Tags/Form/FormTestCase.php
index e204e54e5e..a1b08f89b5 100644
--- a/tests/Tags/Form/FormTestCase.php
+++ b/tests/Tags/Form/FormTestCase.php
@@ -2,6 +2,7 @@
namespace Tests\Tags\Form;
+use Illuminate\Support\Facades\Blade;
use Statamic\Facades\Blueprint;
use Statamic\Facades\Form;
use Statamic\Facades\Parse;
@@ -67,9 +68,14 @@ public function post($uri, array $data = [], array $headers = [])
], $headers));
}
- protected function tag($tag, $params = [])
+ protected function tag($string, $context = [])
{
- return Parse::template($tag, $params);
+ return Parse::template($string, $context);
+ }
+
+ protected function blade($string, $context = [])
+ {
+ return Blade::render($string, $context);
}
protected function createForm($blueprintContents = null, $handle = null)