Skip to content

handleSubmit not being called conditionally #1394

Closed
@msaaddev

Description

@msaaddev

Description

I have a function called handleSubmitForm tied to my form onSubmit. The function does some checks before calling the handleSubmit function of the useChat.

const handleSubmitForm = (e: React.FormEvent<HTMLFormElement>) => {
	e.preventDefault();

	// code

	if (!condition) {
                 // more code
		return;
	}

	handleSubmit(e);
};

The issue arises when the condition fails in handleSubmitForm and it returns without triggering handleSubmit. Now when the condition is met next time, handleSubmit fails to execute. I commented return in the conditional statement and it worked. I then wrapped handleSubmit in an else block like below and then it stopped working again.

const handleSubmitForm = (e: React.FormEvent<HTMLFormElement>) => {
	e.preventDefault();

	// code

	if (!condition) {
                 // more code
		return;
	} else {
                handleSubmit(e); 
	}
};

The same thing happens with append as well. I am stuck because of it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ai/uibugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions