-2

Coming from Contenteditable Height transition

I've quickly realized that a contenteditable div can change from:

 <div contenteditable> </div>

To this:

<div contenteditable style="background-image: none; background-position: 0% 0%; background-repeat: repeat;"><b><i>
    Testing <br> one two three
</i></b><div><b><i><br></i></b></div><div><br></div><div><br></div><div><br></div><div><br></div></div>

Is there an easy way to prevent the user from entering anything other than plaintext and newlines? I will clean it serverside, and can also do some preliminary cleaning through JavaScript, but giving the user the idea that they can make text bold, etc. in the first place is not very good.

Community
  • 1
  • 1
David
  • 15,652
  • 26
  • 115
  • 156
  • So, you want that only `br` elements stay there? What is the purpose of that? – xxxmatko Sep 29 '15 at 09:58
  • Essentially I need it to behave like a textinput. I'm only using contenteditor so it can grow. – David Sep 29 '15 at 09:59
  • I think the downvotes say "just use a text input, dammit". Ok, got it guys. – David Sep 29 '15 at 10:01
  • You need to do it server side, never trust the client. And you can use the same cleaner front-side by listening to the [HTML5 input events](https://developer.mozilla.org/en-US/docs/Web/Events/input) and cleaning the actual content, or with the keyup/keydown events. – dievardump Sep 29 '15 at 10:01
  • How do you post the content and what do you get serverside ? – Brewal Sep 29 '15 at 10:03
  • Some browsers add wrap a `
    ` into a `
    ` when pressing *return* key. You could use [this method](http://stackoverflow.com/a/20398548/2168947) as a workaround
    – Brewal Sep 29 '15 at 10:09

1 Answers1

0

There's none unless you would use a textarea.

orlland
  • 1,256
  • 8
  • 12