May 3, 2021
0
Level 54
Dropdown Being Removed From DOM
I’m faced with a problem I can’t understand what’s happening. Currently when the role is changed and meets the correct criteria of the role then it shows the companies dropdown BUT it removes the dropdown of the roles.
<?php
namespace App\Http\Livewire;
use App\Models\Company;
use Livewire\Component;
class AddRoleForUser extends Component
{
public $selectedRole;
public $showCompaniesDropdown = false;
public function updatedSelectedRole($role)
{
if (!is_null($role)) {
$this->showCompaniesDropdown = in_array($role, ['admin', 'maintainer admin', 'user']);
}
}
public function render()
{
return view('livewire.add-role-for-user', [
'roles' => \Spatie\Permission\Models\Role::get()->pluck('name', 'name'),
'companies' => Company::get()->pluck('name', 'id'),
]);
}
}
<div>
<div class="mb-8">
<x-label
class="text-gray-500"
for="role"
value="Role"
/>
<x-select
wire:model="selectedRole"
id="role"
name="role"
class="block w-full mt-1"
:options="$roles"
/>
</div>
@if ($showCompaniesDropdown)
<div class="mb-8">
<x-label
class="text-gray-500"
for="company"
value="Company"
/>
<x-select
id="role"
name="company"
class="block w-full mt-1"
:options="$companies"
/>
</div>
@endif
</div>
Please or to participate in this conversation.