Included livewire scripts on the page?
Jul 13, 2021
8
Level 1
Livewire form submit not working
Actually form submitted as formal form submits with get method, also not calling submit function.
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use App\Traits\API;
class AddCategory extends Component
{
use API;
public $data;
public $name;
public $color;
public function submit(){
//dd($this->name);
$this->data = $this->callApi([
'endpoint' => 'category/create',
'form_data' => [
'name' => $this->name,
'color' => $this->color,
],
'method' => 'post',
]);
extract($this->data);
if($failed){
foreach($json['errors'] as $key => $error){
$this->addError($key, $error[0]);
}
}
if($successful){
return redirect()->back()->with('success','Category created.');
}
}
public function render()
{
return view('livewire.add-category');
}
}
blade file
@section('page-name')
Add Categories
@endsection
@section('content')
<div class="sales-summary w-100 bg-white border mb-4">
<form wire:submit.prevent="submit" class="flex flex-col w-100 border-1 py-5 px-8">
<div class="flex flex-col mb-4">
<label for="name" class="mb-2 text-base text-gray-700">Category Name</label>
<input type="text" name="name" id="name" class="border-gray-300 focus:shadow-red-900 rounded py-1.5" wire:model="name">
@error('name')<span class="text-red-700 text-xs">{{ $message }}</span> @enderror
</div>
<div class="flex flex-row justify-between mt-5">
<div class="flex">
<a href="{{ url('help') }}" class="transition bg-keppel py-2 rounded px-4 text-white font-semibold tracking-wide mr-3">Help</a>
</div>
<div class="">
<button type="button" class="transition bg-keppel py-2 rounded px-4 text-white font-semibold tracking-wide mr-3">Cancel</button>
<button type="submit" class="transition bg-keppel py-2 rounded px-4 text-white font-semibold tracking-wide">Save</button>
</div>
</div>
</form>
</div>
@endsection
Please or to participate in this conversation.