fix(new-resource): render the resource search binding only on the type step

The searchResources() x-data wrapper was outside the type-step @if that
renders its script, so a direct load of a later step (for example the
PostgreSQL image picker from global search or a reload) threw
"searchResources is not defined".

Closes #12337

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Andras Bacsai
2026-10-26 18:30:10 +01:00
co-authored by Claude Opus 5.5
parent 8d8f8e8988
commit e1637cbe02
2 changed files with 21 additions and 4 deletions
@@ -1,6 +1,6 @@
<div class="application-settings-form" x-data x-init="$wire.loadServers">
<div x-data="searchResources()">
@if ($current_step === 'type')
@if ($current_step === 'type')
<div x-data="searchResources()">
<x-application.settings-section title="Choose a resource" flush>
<x-slot:actions>
<button type="button" class="button" :disabled="loading" @click="loadResources">
@@ -634,8 +634,8 @@
}
}
</script>
@endif
</div>
</div>
@endif
@if ($current_step === 'servers')
<x-application.settings-section title="Select a server"
description="Choose the machine that will host this resource." flush>
@@ -131,3 +131,20 @@ test('the postgresql shortcut ignores a server that is not in the server list',
->assertSet('server', null)
->assertSet('current_step', 'type');
});
test('the postgresql image step does not reference the resource search script it does not render', function () {
Livewire::withQueryParams([
'type' => 'postgresql',
'server_id' => $this->server->id,
'destination' => $this->defaultDestination->uuid,
])->test(Select::class)
->assertSet('current_step', 'select-postgresql-type')
->assertDontSeeHtml('searchResources');
});
test('the resource type step renders the resource search script with its binding', function () {
Livewire::test(Select::class)
->assertSet('current_step', 'type')
->assertSeeHtml('x-data="searchResources()"')
->assertSeeHtml('function searchResources()');
});