How I can make submit button disabled if input field is empty?

Hi Iā€™m using Laravel livewire in form I want to know How I can make submit button disabled if input field is empty?

My Code :smile:

<form wire:submit.prevent="submitForm">
   @csrf
   <div class="input-group">
      <input type="email" wire:model="email" class="form-control" placeholder="email address">
      <button type="submit" class="btn btn-primary" id="newsletter-submit-btn">Submit</button>
   </div>
   @error('email') <div class="text-danger">{{ $message }}</div> @enderror
</form>

Hey, @devhoussam

You can do the following:

public $isDisabled = false;

public function redner()
{
  if (empty($this->email) {
     $this->isDisabled = true;
  }  
}

In your blade:

<button type="submit" disabled="{{ $isDisabled }}"> Submit </button>
1 Like

it display an error ErrorException syntax error, unexpected token ā€œ{ā€ index.blade.php

Not working my friend it make the button disabled but it should remove the disabled when type a character in input field.

public function updatedName($value)
{
  if (!is_empty($value) {
    $this->isDisabled = false;
 }
}