Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

Category Edit - Inline in the Table

Premium
4 min read

Now we will make an editing form. But, differently from the Create form, this time we will make inline editing, so you could edit the category inside the table, without leaving the page.

edit category form

First, we need a public property to know which category will be edited...

The Full Lesson is Only for Premium Members

Want to access all of our courses? (29 h 14 min)

You also get:

54 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

P
phuyer ✓ Link copied!

I think that you need to clear the validation messages when you click "Edit" on a different table row, than the one you are editing. Example (gif animation): https://postimg.cc/nMXX50X6

RB
Rajesh Budhathoki ✓ Link copied!

@phuyer, is cancelCategoryEdit button working for you?

N
Nerijus ✓ Link copied!

Good point for the validation, updated this lesson and repo.

RB
Rajesh Budhathoki ✓ Link copied!

The cancelCategoryEdit button is not working. Also validation bug still presists as mentioned by @phuyer!

N
Nerijus ✓ Link copied!

What's not working for you? As you saw in phuyer animation, the buttons works for him. Validation fixed now.

E
Emruardo ✓ Link copied!

I've had issue with cancel button as well. If I add prevent the click event, it cancels

 <x-primary-button wire:click.prevent="cancelCategoryEdit()">
	 Cancel
</x-primary-button>
FL
Filimoni Lutunaika ✓ Link copied!

Providing each 'x-primary-button' with a unique id works for me.

S
selajdinbilali ✓ Link copied!

Same here cancel not working.

OM
omer mahdi ✓ Link copied!

for the validation bug reset the validation in the editCategory function :-

	public function editCategory($categoryId){
    $this->resetValidation();
    $this->editedCategoryId = $categoryId;
    $this->category = Category::find($categoryId);
}
SK
Syed Khizer ✓ Link copied!

@Filimoni Lutunaika I changed that x-primary-button to span tag and that worked

N
nazzalra ✓ Link copied!

Use hidden class technique just like before. Like this

<td class="@if ($editedCategoryId !== $category->id) hidden @endif px-6 py-4 text-sm leading-5 text-gray-900 whitespace-no-wrap">
		<x-button wire:click="save">
				Save
		</x-button>
		<x-button wire:click.prevent="cancelCategoryEdit">
				Cancel
		</x-button>
</td>
<td class="@if ($editedCategoryId === $category->id) hidden @endif px-6 py-4 text-sm leading-5 text-gray-900 whitespace-no-wrap">

		<x-button wire:click="editCategory({{ $category->id }})">
				Edit
		</x-button>
		<button class="px-4 py-2 text-xs text-red-500 uppercase bg-red-200 rounded-md border border-transparent hover:text-red-700 hover:bg-red-300">
				Delete
		</button>
</td>
N
Nerijus ✓ Link copied!

For classes, at least for me, it's better to use @class() Blade directive

M
muuucho ✓ Link copied!

Could someone point out the direction to go if I want to use the create modal for editing instead of this inline editing?

A
augusto-dmh ✓ Link copied!

Toggle $showModal on editCategory component's method (which gets called when edit button is clicked) and for end-user's readability change the inner text in the modal's button to "Update" instead of "Create", and the modal title to "Edit Category" when $category (or $editedCategoryId, after all one doesn't exists without the other) doesn't have the default "empty" value (for $category, null).

Also make sure to populate the form fields with the category data, and add a closeModal method to reset everything when the modal is closed.

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.