Save contenteditable data
Answered
Atlantic mackerel posted this in #help-forum
Atlantic mackerelOP
Hey guys, I'm trying to save & load my contenteditable div data. I think the algorithm should be like below
onChange event => saveToMongodb (with encoded data)
and when it's not null load data (with decode) from mongodb
Is there better way to do this?
I found some encode / decode systems like
Buffer.from(value).toString('base64'); this
but when the user but too long value, like this,
then the encoded value gonna tooooooo long
Sooo... Maybe is there any way to encode / decode contentEditable data?
onChange event => saveToMongodb (with encoded data)
and when it's not null load data (with decode) from mongodb
Is there better way to do this?
I found some encode / decode systems like
Buffer.from(value).toString('base64'); this
but when the user but too long value, like this,
afsdfsdasdfasdfasdfasdfasdfadfsadsffdsfafdsdfsafdasfdsadfasdfasfdasdfdfasasdfasdfasdfasdfafsdasdfafsdfasdfasdasdfasdfasfdasdfsdfaasdfthen the encoded value gonna tooooooo long
YWZzZGZzZGFzZGZhc2RmYXNkZmFzZGZhc2RmYWRmc2Fkc2ZmZHNmYWZkc2Rmc2FmZGFzZmRzYWRmYXNkZmFzZmRhc2RmZGZhc2FzZGZhc2RmYXNkZmFzZGZhZnNkYXNkZmFmc2RmYXNkZmFzZGFzZGZhc2RmYXNmZGFzZGZzZGZhYXNkZg==Sooo... Maybe is there any way to encode / decode contentEditable data?
5 Replies
Mainly of the file you are using or with the one you are encountering the inconvenience
@Masai Lion Mainly of the file you are using or with the one you are encountering the inconvenience
Atlantic mackerelOP
I don't have git repo 'cause it's simple project for now,
anddd below is my code
or maybe, should I use data-autosave-url option to do this?
anddd below is my code
<div className="focus:outline-none" contentEditable={true} suppressContentEditableWarning={true}
onInput={async (event) => {
let value = event.currentTarget.innerHTML;
const encodedContent = Buffer.from(value).toString('base64');
console.log("encodedContent", encodedContent);
}}>
</div>or maybe, should I use data-autosave-url option to do this?
@aardani why do you need to encode it?
Masai Lion
good point 

Answer