question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Placeholder doesn't work

See original GitHub issue

When summernote gets initialized, the contents get initialized to <p><br></p>. The div is therefore not empty and placeholder doesn’t get shown. Am I missing something here?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:17 (4 by maintainers)

github_iconTop GitHub Comments

19reactions
daveteucommented, Jul 5, 2016

I came here because i have been trying all ways to make the placeholder show over the past 2 days.

If your placeholder is not showing, it is CRUCIAL to ensure your summer note div looks like this

<div id="summernote"></div>

NOT THIS

<div id="summernote"> </div>

ALSO NOT THIS

<div id="summernote">

</div>

Any space between the div will prevent placeholder from showing, and for Firefox, it cause your cursor to start off position too.

on summernote v0.8.1

3reactions
eric-mesaroscommented, Mar 8, 2016

I am using the current version of Chrome v8 of summernote and the placeholder option still does not work.

When summernote gets initialized, the contents get initialized to <p><br></p>.

Yes, I see that; however I believe that’s a bit of a gotcha. Also, clicking into the editor and hitting backspace to remove the initial paragraph still does not display the placeholder. When I look in the DOM there is in fact a placeholder element of class=“note-placeholder”; however it never shows up.

This was my fix…

var elem = $(".summernote").summernote({
    placeholder: "Enter Text Here...",
    callbacks: {
        onInit: function () {
            var editor = elem.next(),
                placeholder = editor.find(".note-placeholder");

            function isEditorEmpty() {
                var code = elem.summernote("code");
                return code === "<p><br></p>" || code === "";
            }

            editor.on("focusin focusout", ".note-editable", function (e) {
                if (isEditorEmpty()) {
                    placeholder[e.type === "focusout" ? "show" : "hide"]();
                }
            });
        }
    }
});

Overall I really like this editor!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Input Field Placeholder not working.? - Stack Overflow
Placeholder doesn't work for Inputs that are not the types text so you will have to use value in your case like this...
Read more >
Don't Use The Placeholder Attribute - Smashing Magazine
The presence of a placeholder attribute won't be flagged by automated accessibility checking software. However, this doesn't necessarily mean ...
Read more >
Html-placeholder does not work with input Field
Note: The placeholder attribute works with the following input types: text, search, url, tel, email, and password. Share.
Read more >
::placeholder | CSS-Tricks - CSS-Tricks
:placeholder-shown, being a pseudo-class, has to select an existing element – it selects the input whenever you're in the placeholder-showing ...
Read more >
HTML5 Forms: Placeholder Type Attribute - Wufoo
The spec says placeholder should only work on text, search, url, tel, email, password and number input types. Browsers that support the placeholder...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found