Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rritvik's avatar

Not able to add select2

@if($account_type == 'debit')
                <div class="subaccountsfileds" >
                    <div class="form-group col-span-6 sm:col-span-4" wire:ignore>
                        <label for="exampleFormControlInput4" class=""> Account </label>
                        <select  class=" newdata form-control" name="subaccount" wire:model="subaccount" id="newsubaccount">
                            <option value="">Select Account</option>
                            <optgroup label="Income">
                                @foreach($income as $account)
                                    <option value="{{$account['id']}}">{{ucfirst(str_replace('-',' ',$account['name']))}}</option>
                                @endforeach
                            </optgroup>
                            <optgroup label="Expense">
                                @foreach($expense as $account)
                                <option value="{{$account['id']}}">{{ucfirst(str_replace('-',' ',$account['name']))}}</option>
                                @endforeach
                                </optgroup>
                            <optgroup label="Profit Expense">
                                @foreach($profit as $account)
                                <option value="{{$account['id']}}">{{ucfirst(str_replace('-',' ',$account['name']))}}</option>
                                @endforeach
                            </optgroup>
                        </select>
                    </div>
                </div>
            @endif

This is my code, and when the condition satisfies div is shown, but after that I am not able to add select2 to the newsubaccount id

Please help, thanks

0 likes
2 replies
rritvik's avatar

@enadabuzaid , thanks for the links I got a look of how to implement select2 with livewire, and I implemented those changes and all my select are working fine, but this div show based on other select option, and when this shows the select2 changes does not takes place.

I have tried putting it out of if condition and then implementing select2, it working fine then

Please or to participate in this conversation.