Search code examples
javascriptlaravelformslivewires

Auto submit form with setTimerOut() in livewire


I have a livewire form, the data do submit if i click submit button. i want the form to auto submit after 5 minutes. i have tried the below code the data is not submiting but refesh the page after the set time. Any help please.

<form id="steps" wire:submit.prevent="postQuiz" class="show-section" name="quiz">
 
  <button class="next" type="submit"><span>Submit</span></button>
</form>

<script>
  window.onload=function(){
    window.setTimeout(function() { document.quiz.submit(); }, 300000);
  };
</script>

Solution

  • You can use @this blade directive to call a method from your component

    <script>
      window.onload=function(){
        window.setTimeout(function() { @this.postQuiz(); }, 300000);
      };
    </script>