emojionearea icon indicating copy to clipboard operation
emojionearea copied to clipboard

Reset input field after ajax complete

Open squaddie opened this issue 5 years ago • 4 comments

Sorry for my English!

Hi, I have a problem. I initialize plugin after page load. Open modal window, type some text in field with emoji, than I pick emoji and send it to the server. If response code 200, I want to reset all the fields. If I type this $('#some_form').trigger('reset') this will work for every input exept emojione. So I going to do next thing var emojioneAreas = $(".em").emojioneArea(); emojioneAreas.data("emojioneArea").setText('');

And field is reset but, the content of this field don't present in new FormData object. So tell me pleas, how can I send date via ajax, reset all inputs in form, and fill the form again, without any pain.

squaddie avatar Aug 24 '19 18:08 squaddie

emojioneAreas.data("emojioneArea").setText(''); should reset your input, I don't know how works your form, but probably you should create new FormData() after emojioneAreas.data("emojioneArea").setText('');

mervick avatar Aug 24 '19 21:08 mervick

emojioneAreas.data("emojioneArea").setText(''); should reset your input, I don't know how works your form, but probably you should create new FormData() after emojioneAreas.data("emojioneArea").setText('');

I bind submit event and my FormData created every time submit event is triggered. So firstly I create new FormData and send it via ajax. If ajax response 200, I am going to emojioneAreas.data("emojioneArea").setText(''); and this $('#some_form').trigger('reset') after all this steps done form is reset and it's looks like everything ok, but when I fill the form again, new FormData object don't have input with .em class, which is initialized by emojioneArea.

squaddie avatar Aug 25 '19 11:08 squaddie

Why not just append the emojiOneAreas to your FormData manually using formData.append?

carpii avatar Aug 25 '19 11:08 carpii

Why not just append the emojiOneAreas to your FormData manually using formData.append?

I think about it, and probably I will go this way. But it's would be cool to have cleaner way to fill formdata object

squaddie avatar Aug 25 '19 12:08 squaddie