skip to Main Content

I have this button in the blade file of a livewire component:


<button type="button" title="Adauga o disciplina noua" class="ml-2 my-auto bg-blue-500 text-white px-2 py-1 rounded-lg" onclick="adaugaSelect()">+</button>

and the function:

`
@script
<script>
    function adaugaSelect() {
        
    }
</script>
@endscript`

And in console I get Uncaught ReferenceError: adaugaSelect is not defined . From what i read there might be an issue with the @script directive.

Is there any fixes?

googling and moving the function outside the blade file, but is not doable

2

Answers


  1. I also have noticed this issue in livewire3 .. I solve it by not using @script at all.. at will work without that just fine… here is an example

    <div>
        <button onclick="myFunction()">Click me</button>
    </div>
     
    @script
    <script>
        function myFunction() {
            alert('Hello World!');
        }
    </script>
    @endscript
    

    thats showing error just like yours…

    so i just remove the @script tag

    <div>
        <button onclick="myFunction()">Click me</button>
    </div>
    
    <script>
        function myFunction() {
            alert('Hello World!');
        }
    </script>
    

    back in livewire V2 you will find that they where using @push("scripts") but it was also not working for me…

    Login or Signup to reply.
  2. apparently the @script … @endscript issue was solved on Livewire version 3.3

    try to update the Livewire package

    composer update livewire/livewire

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search