Skip to content

Commit

Permalink
Allow ID to be overridden by event
Browse files Browse the repository at this point in the history
  • Loading branch information
bencroker committed Aug 21, 2024
1 parent 7ff54eb commit 1ae48f4
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/services/ComponentsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,6 @@ public function create(string $value, array $variables = [], array|string $attri
$attributes = ['id' => $attributes];
}

// Allow ID to be overridden, otherwise ensure random ID does not start with a digit (to avoid a JS error)
$id = $attributes['id'] ?? ('component-' . StringHelper::randomString(6));
$config->id = $id;

$mergedVariables = array_merge(
$variables,
Sprig::$core->requests->getVariables()
Expand All @@ -233,6 +229,10 @@ public function create(string $value, array $variables = [], array|string $attri
$mergedVariables = $event->variables;
$attributes = $event->attributes;

// Fall back to a random ID that does not start with a digit (to avoid a JS error)
$id = $attributes['id'] ?? ('component-' . StringHelper::randomString(6));
$config->id = $id;

$componentObject = $this->createObject($value, $mergedVariables);

if ($componentObject) {
Expand Down

0 comments on commit 1ae48f4

Please sign in to comment.