Bootstrap modal decendent dropdown not working

For storing data I’m using the bootstrap modal.
But the problem I faced In my modal that is decendent dropdown is not working using wire:ignore method if I removed this wire:ignored method then modal hides.
Can anyone tell me how to get rid of this situation…
This is my LIvewire component methods

<?php

namespace App\Http\Livewire\Poi;

use App\Poi as AppPoi;
use Livewire\Component;
use App\Tbl_productcategory;
use App\Tbl_product_subcategory;

class Poi extends Component
{
    public $product_name;
    public $user_id;
    public $product_category_id;
    public $sub_category_id;
    public $isActive;
    
    public $subcategories = [];

    public function store()
    {
        $validatedData = $this->validate([
            'product_name' => 'required',
            'product_category_id' => 'required',
            'sub_category_id' => 'required',
        ]);

        $validatedData['user_id'] = auth()->user()->id;

        AppPoi::create($validatedData);

        session()->flash('message', 'Row data successfully created.');

        $this->reset();

    }

    public function render()
    {
        try {
            if (!empty($this->product_category_id)) {
                $this->subcategories = Tbl_product_subcategory::where('procat_id', $this->product_category_id)->get();
            }
            return view('livewire.poi.poi')->with([
                'product_of_interests' => AppPoi::get(),
                'categories' => Tbl_productcategory::has('tbl_product_subcategory')->get(),
            ]);
        } catch (\Throwable $th) {
            dd('catch exception', $th->getMessage());
        }
    }
}

THis is livewire blade

<div wire:ignore>
    <!-- Modal -->
    <div class="modal fade" id="poiModal" tabindex="-1" aria-labelledby="poiModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="poiModalLabel">Add New</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <form wire:submit.prevent="store">
                    <div class="modal-body">
                        <div class="form-group">
                            <label for="product_name">Product Name</label>
                            <input wire:model="product_name" type="text" class="form-control" id="product_name" placeholder="eg: shoes">
                        </div>
                        <div class="form-group">
                            <label for="product_category_id">Category</label>
                            <select class="form-control required"
                                wire:model="product_category_id" name="product_category_id" id="product_category_id">
                                <option value="0">Select Category</option>
                                @foreach($categories as $cat)
                                    <option value="{{ $cat->procat_id }}">{{ $cat->category }}</option>
                                @endforeach
                            </select>
                        </div>
        
                        <div class="form-group">
                            <label for="sub_category_id">SubCategory</label>
                            <select class="form-control required"
                                wire:model="sub_category_id" name="sub_category_id" id="sub_category_id">
                                <option value="">select subcategory</option>
                                @foreach($subcategories as $subcat)
                                    <option value="{{ $subcat->prosubcat_id }}">{{ $subcat->category }}</option>
                                @endforeach
                            </select>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                        <button type="button" class="btn btn-primary">Save changes</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

Are you using dispatchBrowserEvent and JS for handle the modal? That give me some more work but fix the bugs that modals Bootstrap have in Livewire

No…I’m using simple bootstrap modal…

I suggest you first look at that…and the wire:ignore I think that you have to put in the select div parent

<div class="form-group" wire:ignore>
                            <label for="product_category_id">Category</label>
                            <select class="form-control required"

okk, if I put this wire:ignore on category div…Then modal not working means if I type a string in input box then modal hides…

First follow this tutorial for the dispatchBrowserEvent and JS using modal Bootstrap. After you can focus in the wire:ignore if it’s necessary. In the chapter 3 and 4 you can see about modals in Livewire

@prospero okk thank you I will watch this…

Ok. After if you want share the results or issues here and we can learn about it jjj. Greetings

@prospero instead of wire:ignore I used wire:ignore.self now its working…
And thank for refrencing the video…I learned/understand how to use dispatchBrowserEvent…

Ok, I’m glad to heard that! Good source code then! :+1:

1 Like