Comment component messages in event handlers?

Hi

I'm using the comment component, and I'd like to send the messages to my API. I've added a "Submit" event handler which triggers a query. However, I have no idea how to get the content of the submitted comment. All I can see to try is {{comment1.newCommentValue}} but when triggered this appears to be an empty string. The new comment also hasn't appeared in {{comment1.comments}} yet. How do I get the new comment?

Thanks

Hi @kpk-frec!

The comments are stored in the comment1.comments array (see area (2) in my screenshot), so if you'd like to grab the most recent comment, you'll just need to grab the last comment object in the array (see area (3) in my screenshot).

Let me know how this works for you!

Victoria

I can get it that way, but I can't seem to reach it from the "Submit" event handler.

Ah, interesting! It seems like the event handler might be running before the comment gets posted. We can probably figure out a different way together, let me see! :slight_smile:

I think I'll just use a textarea and button to reproduce the functionality, but it might be worth raising a bug to fix this, because the event has limited value if you can't access the message :slight_smile:

Absolutely! I'll create an internal request for this now. Using a text area sounds great in the meantime + thank you for surfacing this!

Hey, any update on this? I am having the same issue - the event handler is running before the comment is submitted

actually I added a debounce and that seems to work

2 Likes

Circling back with an update -- thank you all for your feedback on how this ergonomic aspect of the comment component could be improved! Thanks for confirming the workaround worked for you @charlie123 !

As of July 31 on Cloud, and in the 3.75 table release version for Self-hosted, this should be fixed by default so you may not need to use the debounce workaround anymore.

As part of the revamped new Comment Thread component (announced here New: Comment Thread), our eng team made an update to delay the clear so that on submit, the submit handler can still read commentThread1.value:

If you are on the earlier version (the old Comment component), you'll need to upgrade to the new component version with the one click upgrade option on the editor to take advantage of the newer improvements.

This should solve for the issue where with the submit handler, builders had a harder time getting the "just submitted" value and needed to implement a timed wait. Try out the comment thread, and if you have questions or feedback about configuring it, please create a new topic here on the forum!