Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete button does not work #70

Open
rbtsv opened this issue Nov 21, 2024 · 2 comments
Open

Delete button does not work #70

rbtsv opened this issue Nov 21, 2024 · 2 comments

Comments

@rbtsv
Copy link

rbtsv commented Nov 21, 2024

            <DropdownMenuItem>
              <form action={deleteProduct}>
                <button type="submit">Delete</button>
              </form>
            </DropdownMenuItem>

The delete button from dropdown menu does not work. A click on the button does not invoke the submit event (I used () => {alert("test");} instead of deleteProduct as well). I had to use onClick method to make things work.

@tehtipsy
Copy link

tehtipsy commented Dec 9, 2024

you can add a hidden input field inside the form with the id from the product provided to the component.

         
           // product.tsx
           import { deleteProduct } from './actions';

           // ...
             <DropdownMenuItem>
               <form action={deleteProduct}>
                 <input type="hidden" name="id" value={product.id} />
                 <button>
                    Delete
                 </button>
               </form>
           </DropdownMenuItem>
   
           
           // actions.ts
           "use server";
           
           export async function deleteProduct (formData: FormData) {
             let id = Number(formData.get('id')); // key is set by the input field "name" attribute
             await deleteProductById(id);
             revalidatePath('/');
           }

@rbtsv
Copy link
Author

rbtsv commented Dec 10, 2024

But how will it fix that the submit event does not work? Currently I have solved this problem via onClick event, but it is definitely a bug)

OumaIntissar pushed a commit to OumaIntissar/nextjs-postgres-nextauth-tailwindcss-template that referenced this issue Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants