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

InputValue Handling #37

Closed
Satoshi-Sh opened this issue Jan 13, 2024 · 3 comments · Fixed by #45
Closed

InputValue Handling #37

Satoshi-Sh opened this issue Jan 13, 2024 · 3 comments · Fixed by #45
Assignees
Labels
bug Something isn't working

Comments

@Satoshi-Sh
Copy link
Contributor

Describe the bug

This bugs were mentioned by @Arol15

  1. clear the input field after a message has been successfully posted;
  2. fix TS warning for this line: const text = form.get("message").valueOf(); - text can be null;
  3. make input field required or disable send message button if no input entered;

Steps to reproduce

  1. Go to a chat room.
  2. Submit the empty string. You can see the party server received the empty text
  3. Put any message in the input field. The message stays after submission.

Expected behavior

  • Users should not be able to submit an empty text.
  • Input field should be cleared after submission.

Screenshots

input-demo

Possible Solution

Right now, we use the FormData to get the input value

const form = new FormData(event.target as HTMLFormElement);
          const text = form.get("message").valueOf();

I think it's better to utilize useState for inputValue to reset the input field after submission.

I would add const [inputValue, setInputValue] = useState(""); to the line 15,
add value={inputValue} onChange={(e) => { setInputValue(e.target.value); }} to the input element at the line 52,
and modify form onSubmit like this

<form
        className="mt-2 flex flex-col gap-4"
        onSubmit={(event) => {
          if (inputValue !== "") {
            socket.send(JSON.stringify({ user: username, text: inputValue }));
            setInputValue("");}
          event.preventDefault();
        }}
      >
@Satoshi-Sh Satoshi-Sh added bug Something isn't working needs triage issue waiting to be triaged labels Jan 13, 2024
Copy link

Thanks for the issue, our team will look into it as soon as possible! If you would like to work on this issue, please wait for us to decide if it's ready. The issue will be ready to work on once we remove the "needs triage" label.

To claim an issue that does not have the "needs triage" label, please leave a comment that says ".take".

For full info on how to contribute, please check out our contributors guide.

@nickytonline
Copy link
Owner

nickytonline commented Jan 13, 2024

It's currently an uncontrolled input. I opted to not use component state. Once it runs socket.send, you can run form.reset() and it will clear the message.

@nickytonline nickytonline removed the needs triage issue waiting to be triaged label Jan 13, 2024
@Arol15
Copy link
Contributor

Arol15 commented Jan 13, 2024

.take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants