Placeholders.js icon indicating copy to clipboard operation
Placeholders.js copied to clipboard

Feature request: Multiline placeholders in text area

Open Faek opened this issue 11 years ago • 2 comments

I know that new lines are not supported as part of the HTML5 spec, but in some cases it's very useful to display a placeholder with multiple lines in a text area. Interestingly, when I tested this plugin on IE6 it behaved as I would like placeholders to behave (Multiline, don't submit placeholder data to server)

I tried to change this line: Placeholders.nativeSupport = test.placeholder !== void 0; to Placeholders.nativeSupport = false;

to just force the placeholder js to execute on modern browsers (tested in FF 27) and it actually did show the placeholder as multiline, however, when I submitted my form, the placeholder text was submitted to the server even though it looked like it was being cleared out.

So anyway, my feature request is to have an option that could be turned on or off to detect multiline placeholders in textareas and apply the js polyfill to those even on modern browsers.

Faek avatar Feb 19 '14 00:02 Faek

I'm assuming you're trying to create multiline placeholders by adding \n characters to the placeholder attribute value? That will work when Placeholders.js is active because it just sets the value of the textarea, where new lines are allowed. If anything, I think that's an oversight and that functionality should be removed (by stripping new lines before setting the value) so the behaviour matches the spec more closely.

However I am considering adding various new options for the next version and will think about this.

jamesallardice avatar Feb 19 '14 08:02 jamesallardice

Yes you are correct, I'm just putting a newline (\n) inside of the placeholder attribute. I agree the feature I'm requesting would definitely have to be something that could be toggled on and off since it behaves differently from the spec, and also would be doing "javascript based placeholder work" on browsers that natively support placeholders in order to achieve the multi line placeholder.

Would think a nice way to do it would be to always strip newlines in placeholders in order to match the spec, but then allow a configuration option that would be something like multiline: [true|false] If it were false, newlines would be stripped from placeholders in all cases to match the spec (and this would be the default). If it were true, newlines would not be stripped, and textareas with newlines would use a JS-based placeholder regardless of whether or not the browser natively supports it, in order to show placeholders with multiple lines in textareas no matter what browser.

Thank you for considering my idea. For now I will use a different solution in order to achieve the multi-line placeholders in modern browsers, but will definitely be watching this spot because I feel that Placeholders.js is the best placeholder polyfill.

Faek avatar Feb 19 '14 15:02 Faek