loading...

re: Rich text editing on the web: Getting started with Draft.js VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Hey Rose, a little question about draft-js is there a way to control how many images can user insert? Thanks
 

Hey! A slightly complicated answer: Yes you can but....

By default out-of-the-box draft.js doesn't support images at all. It's fairly simple to add basic support:

there's an article here: medium.com/@siobhanpmahoney/buildi...
Or you can use something like this pre-built plugin: draft-js-plugins.com/plugin/image

From there you'd have to add some kind of control for maximum images on your end and enforce the rule. Since you are the one that controls editorState being updated at all times, you have the power to veto any change. With images, if they are being added by a user through a button, you could disable the button whenever they exceed a total number of images, and re-enable when they are under the maximum. Tracking total images should be fairly simple by using the onChange callback by searching for and counting total number of the custom image entity, or you could check on-the-fly whenever the button is clicked.

 

Wow Rose, thanks alot for such a deep answer wasn't expecting it.
Also a great article surely will keep following!

code of conduct - report abuse