values in modal

I'll send a warning message to the user when they make an error in a component within a modal. However, after sending the warning message, I want the user's old messages to be visible when they reopen the old modal. Is the modal's content deleted when the interaction is replied to? Is there any documentation on this? When is the values of a modal deleted?
16 Replies
d.js toolkit
d.js toolkitβ€’3w ago
Mafia
Mafiaβ€’3w ago
You would need to store the value that the user inputted and if they recreate the modal you set those stored values as the values in the modal interactive components
d.js docs
d.js docsβ€’3w ago
:method: TextInputBuilder#setValue() builders@1.13.0 Sets the value for this text input.
ZeuLeg
ZeuLegOPβ€’3w ago
Yes, I can do this manually, but Discord does this too, and I'm wondering when Discord does this. For example, when the modal interaction doesn't have a response?
Mafia
Mafiaβ€’3w ago
You have no control over what Discord does. Once the modal is submitted, Discord clears the cached data
ZeuLeg
ZeuLegOPβ€’3w ago
I guess the modal is not deleted when there is no response. I tried But it is necessary to close the modal manually.
Mafia
Mafiaβ€’3w ago
What do you mean? Close the modal manually?
ZeuLeg
ZeuLegOPβ€’3w ago
When you open the modal, type something into it, close the modal screen by pressing the cancel key, and then reopen the same modal, the last text you entered will be displayed.
Mafia
Mafiaβ€’3w ago
Yes, that information is cached on the client by Discord. There is no way or it to be controlled by your application
ZeuLeg
ZeuLegOPβ€’3w ago
:/
Ashish
Ashishβ€’2w ago
I mean one way to ensure that doesn't happen is to have a different identifier each time Understood, thanks for the explanation
!                 𝐂𝐙‒ Solo
discord does this only if the modal was not submitted and user closes the modal with some data filled in. So, during an error like let's say the modal interaction was not replied in time, the submit will fail and the user closes the modal. Then discord will save their data as the modal was not submitted. But if the modal was submitted without an error (the interaction was replied to/deferred on time), discord won't save it. I hope I'm explaining the right thing 😭 I don't know if this will work but maybe we could do something like this: if the submitted values are not valid as per your design, you could reply to the button interaction which showed the modal with .followUp() saying what's wrong and not reply to the modal's interaction (return; after replying to the button interaction). But since this won't close the modal window, the user might not see what's wrong until they close the modal window themselves (they will probably do because of the submit button not working). Note: I am assuming you're using a button's interaction to show the modal but this would work with select menu and chat input command interactions as well.
ZeuLeg
ZeuLegOPβ€’3d ago
There's no need to compromise the user experience by leaving the modal open. I'll save the values ​​manually if necessary. (I'm showing this modal with a slash command.)
!                 𝐂𝐙‒ Solo
yes that's the best choice, but I was wondering this... will it work with File Upload components too?
ZeuLeg
ZeuLegOPβ€’3d ago
I haven't tried it but for me the file upload component is not needed.
!                 𝐂𝐙‒ Solo
I see, then it's fine 😌

Did you find this page helpful?