Skip to content

Commit

Permalink
Fix(web-twig): Render input and main props if the prop value is not `…
Browse files Browse the repository at this point in the history
…null` or empty
  • Loading branch information
dlouhak authored and literat committed Jun 11, 2023
1 parent c168eea commit 09212b6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/web-twig/src/Resources/partials/inputProps.twig
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{%- for propName, propValue in transferringAttributes %} {{ propName }}="{{ propValue }}"{% endfor -%}
{%- for propName, propValue in transferringAttributes %}{%- if propValue is not null and propValue != '' %} {{ propName }}="{{ propValue }}"{% endif -%}{% endfor -%}
2 changes: 1 addition & 1 deletion packages/web-twig/src/Resources/partials/mainProps.twig
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{%- if id != null %} id="{{ id }}"{% endif -%}{%- for propName, propValue in transferringAttributes %} {{ propName }}="{{ propValue }}"{% endfor -%}
{%- if id != null %} id="{{ id }}"{% endif -%}{%- for propName, propValue in transferringAttributes %}{%- if propValue is not null and propValue != '' %} {{ propName }}="{{ propValue }}"{% endif -%}{% endfor -%}
6 changes: 4 additions & 2 deletions packages/web-twig/src/Twig/PropsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function renderMainProps(Environment $environment, $props = [], $allowedA
// allow manually specified attributes
|| in_array($propName, $allowedAttributes)
) {
if ($propValue !== '') {
if (! is_null($propValue) && $propValue !== '') {
$transferringAttributes[$propName] = $propValue;
}
}
Expand All @@ -76,7 +76,9 @@ public function renderInputProps(Environment $environment, array $props, $allowe
$transferringAttributes = [];
foreach ($props as $propName => $propValue) {
if (in_array($propName, self::VALIDATION_ATTRIBUTES, true) || in_array($propName, $allowedAttributes)) {
$transferringAttributes[$propName] = $propValue;
if (! is_null($propValue) && $propValue !== '') {
$transferringAttributes[$propName] = $propValue;
}
}
}

Expand Down

0 comments on commit 09212b6

Please sign in to comment.