【发布时间】:2021-08-28 17:48:07
【问题描述】:
首先我创建一个表单并将其连接到功能但它有两个按钮和一个用于表单提交的按钮和另一个用于重置所有内容的按钮。但是,如果按下任何按钮,它将在运行 resetcategory() 函数后提交,但在运行 submitcategory() 后,我无法使用 if($this->name) 的一些解决方法,但我不想使用它。请帮忙?
我的 php livewire 文件是
public function resetcategory()
{
$this->reset();
}
public function submitcategory()
{
if ($this->name)
{
Category::create([
'name' => $this->name,
'parent' => $this->parent,
]);
$this->reset();
}
}
我的刀片文件是---
<form wire:submit.prevent="submitcategory">
<div class="flex items-center justify-end px-4 py-3 bg-gray-50 text-right sm:px-6 shadow sm:rounded-bl-md sm:rounded-br-md">
<!-- here is input content-->
<button class="inline-flex items-center px-4 py-2 bg-gray-800 border border-transparent rounded-md font-semibold text-xs text-white uppercase tracking-widest hover:bg-gray-700 active:bg-gray-900 focus:outline-none focus:border-gray-900 focus:ring focus:ring-gray-300 disabled:opacity-25 transition mr-2 ml-2" wire:click="resetcategory()">Reset</button>
<button type="submit" class="inline-flex items-center px-4 py-2 bg-gray-800 border border-transparent rounded-md font-semibold text-xs text-white uppercase tracking-widest hover:bg-gray-700 active:bg-gray-900 focus:outline-none focus:border-gray-900 focus:ring focus:ring-gray-300 disabled:opacity-25 transition">Send</button>
</div>
</form>
【问题讨论】:
标签: php laravel laravel-livewire