Vue: Textarea's initial value is emptied in component if it contains html tags

Created on 7 Mar 2017  路  4Comments  路  Source: vuejs/vue

Jsfiddle vue v2.2.1: https://jsfiddle.net/dobuznsc/1/
Jsfiddle vue v1.0.12: https://jsfiddle.net/dobuznsc/2/

As you can see, there're 3 textareas and inputs in 3 different scopes:

  • out of vue / body scope: textarea and input values as preserved, as expected
  • root vue instance scope: textarea and input values are preserved, as expected
  • component scope: input value is preserved, textarea's is not (in v2), however, they are preserved in v1

My question is, why are textareas in root and component scope handled differently, is this a bug?

contribution welcome improvement

Most helpful comment

Technically we can make the HTML parser treat the entire content of <textarea> as a string. This could use a PR if anyone is up for it.

All 4 comments

Because the component template is compiled by vue while the other one is interpreted by the browser before vue can compile it.
Inside of textareas only text can be entered, therefore when Vue tries to put HTML inside of it, the browser probably ignores that. What you actually want is to write an escaped version of it: <textarea>&lt;p&gt;Component textarea&lt;/p&gt;</textarea>

Maybe we could add a development warning, but basically, you cannot write unescaped HTML inside of a textarea. More specifically, you can only write text. The browser escapes it for convenience I guess.

Great, makes sense, it works with escaped HTML. I didn't even think about escaping since it worked in v1.

Technically we can make the HTML parser treat the entire content of <textarea> as a string. This could use a PR if anyone is up for it.

I can try that, I'm not sure I will manage to do that but I will try

Was this page helpful?
0 / 5 - 0 ratings

Related issues

paceband picture paceband  路  3Comments

6pm picture 6pm  路  3Comments

seemsindie picture seemsindie  路  3Comments

bdedardel picture bdedardel  路  3Comments

paulpflug picture paulpflug  路  3Comments