manhcodedao / jquery-watermark

Automatically exported from code.google.com/p/jquery-watermark
0 stars 0 forks source link

Enhancement - Multi Element apply, different text for each element using "placeholder" attribute #62

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hi there,

Really like your plugin, saved me the trouble of making my own

However, i really wanted to use this as a polyfill for browsers that dont 
support placeholder natively. 

What this means, is that i wanted, when i called the plugin on a collection 
(e.g. $(':text')), the plugin to read the "placeholder" attribute of each 
element and use that as the text of the watermark.

I achieved this rather simply, by adding a simple option called
"usePlaceHolder" and by adding the following code after 

return this.each(
    function () {
        var $input = $(this);

/*------------------NEW CODE-----------------*/
        if (options.usePlaceHolder) {
            text = $input.attr('placeholder');
        }
/*-------------------------------------------*/

And call the plugin like so:
$(':text').watermark("", { usePlaceHolder: true });

That's it. A nice change for those who need it

Original issue reported on code.google.com by dog...@gmail.com on 23 Jun 2011 at 12:54

Attachments:

GoogleCodeExporter commented 8 years ago
I am an idiot i did not set this as an enchancement :(

Original comment by dog...@gmail.com on 23 Jun 2011 at 12:54

GoogleCodeExporter commented 8 years ago
Thanks for the feedback.

I was thinking of maybe adding an option called "textAttr" that would accept a 
string name of an attribute, the value of which you want to automatically turn 
into watermark text.

So, if options.textAttr is set to "placeholder", whatever value is in the 
placeholder attribute would become the watermark text when .watermark() is 
called on the element.  (Or if native watermarks are supported, nothing would 
happen to the element.)

Doing it this way would also allow people to use other attributes, such as 
title, for the watermark text.

Original comment by t...@speednet.biz on 21 Jul 2011 at 10:52

GoogleCodeExporter commented 8 years ago
well? :)

Original comment by marekda...@gmail.com on 20 Mar 2013 at 12:14

GoogleCodeExporter commented 8 years ago
Hello,

first of all, great js library. It does everything I need it to do. I found 
several others that would do only partially what I needed, but this one does it 
all.

I added the new code to your script library that dog...@gmail.com posted as I 
am setting the placeholder attribute on my fields. Hope you don't mind.

Also, I'd like to post this solution on my XPages blog for other Lotus Notes / 
XPages developers out there, so, I was wondering if you'd mind me doing that?

Of course I would give you and dog...@gmail.com proper credit.

Thank you and have a nice day.

Daniel

Original comment by t.d.frie...@gmail.com on 15 Aug 2014 at 8:38

GoogleCodeExporter commented 8 years ago
Sorry for the massive delay. I got a time slice and made some changes to 
support setting watermarks via attribute values.  The changes are a bit more 
extensive than the 3 lines of code suggested, since that is not really bullet 
proof, and it also supports leaving off the empty string argument and just 
passing the options object.

I'll try to get the new version posted within a day.

Original comment by t...@speednet.biz on 15 Aug 2014 at 10:28

GoogleCodeExporter commented 8 years ago
This issue is fixed in the latest release (3.2.0).  I would strongly recommend 
using the latest release rather than the 3-line quick fix above, as the 
quick-fix above may introduce other problems.

The fix adds a new option called "textAttr", which allows you to specify any 
attribute from which to generate the watermarks.  The Project Home page 
includes a description and instructions for implementing in your pages.

Original comment by t...@speednet.biz on 16 Aug 2014 at 4:52

GoogleCodeExporter commented 8 years ago
Hello,

this is perfect! Thank you very much for putting that into your code, I do 
appreciate it.

It works perfectly, no issues whatsoever.

Great work, well done!!

Original comment by t.d.frie...@gmail.com on 25 Aug 2014 at 10:14