[whatwg] Should editable elements have placeholder attribute?
Alfonso Martínez de Lizarrondo
amla70 at gmail.com
Wed May 2 11:41:44 PDT 2012
FWIW:
Recently I wrote such a plugin for CKEditor, it can be tested here:
http://alfonsoml.blogspot.com.es/2012/04/placeholder-text-in-ckeditor.html
I don't think that too many people request this feature, but that might be
simply because there are other bigger problems and they don't want to waste
the time with these details :-)
In my checks to see if the editor is empty I decided that empty means no
real content, only a paragraph or new line, and of course every browser
decided that clearing the content might mean a different default content
In the end this is the check that I'm using at the moment (I didn't perform
extensive tests, just enough to check that it seemed to work)
var value = data.replace( /[\n|\t]*/g, '' ).toLowerCase();
if ( !value || value == '<br>' || value == '<p> <br></p>' || value ==
'<p><br></p>' || value == '<p> </p>' )
return true;
Regards
2012/5/2 David Young <dyoung at pobox.com>
> On Wed, May 02, 2012 at 01:02:10PM +0300, Aryeh Gregor wrote:
> > On Wed, May 2, 2012 at 9:59 AM, Ryosuke Niwa <rniwa at webkit.org> wrote:
> > > Great. I think the tricky part will be defining exactly how and when
> the
> > > placeholder is displayed.
> > >
> > > e.g. Should it be treated as if there is a text node in the editable
> > > element? Should we ignore things like "<br>" or collapsible spaces when
> > > determining whether the element is empty or not?
> >
> > Currently the spec isn't clear about this for <input>, so I don't
> > think it needs to specify exactly for <textarea> or contenteditable
> > either. It can be left as a UI decision. As far as QoI goes, I think
> > you'd want to display it as long as there's no visible text or images
> > or things. <p><br></p> should still display the placeholder, and
> > probably so should <p><font color=red><br></font></p>, etc. As long
> > as there's no text (or <img>, etc.) that's visible to the user -- if
> > it *looks* empty, the placeholder should display.
>
> I think that what you describe may hide state from the user (e.g., hides
> the style that will apply) and limits which positions you can point at
> with the mouse.
>
> A better alternative is that <p><br></p> displays a character that holds
> the position of the <br> and indicates its presence. You could use a
> return symbol, ⏎, or interpunct, ·, for the purpose. In the example
> <p><font color=red><br></font></p>, color that character red.
>
> Dave
>
> --
> David Young
> dyoung at pobox.com Urbana, IL (217) 721-9981
>
More information about the whatwg
mailing list