frozaelf / jquery-datatables-column-filter

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

Use placeholder in input text #101

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I suggest a solution to create a input text using placeholder ...

in line 288 : Replace  label = $(this).text(); //"Search by " + $(this).text(); 
by label = $.trim($(this).text()); //"Search by " + $(this).text();
in line 68 : Replace input.focus(function () {
                if ($(this).hasClass("search_init")) {
                    $(this).removeClass("search_init");
                    this.value = "";
                }
            });
            input.blur(function () {
                if (this.value == "") {
                    $(this).addClass("search_init");
                    this.value = asInitVals[index];
                }
            });
by 
        if (Modernizr.input.placeholder) {
            input.attr("placeholder", "search")
        } else {
            input.focus(function () {
                if ($(this).hasClass("search_init")) {
                    $(this).removeClass("search_init");
                    this.value = "";
                }
            });
            input.blur(function () {
                if (this.value == "") {
                    $(this).addClass("search_init");
                    this.value = asInitVals[index];
                }
            });

        }
or use a plugin like jquery (http://code.google.com/p/jquery-watermark/).

Attached to this issue, the script modified.

Original issue reported on code.google.com by jerome.d...@gmail.com on 10 Oct 2012 at 11:01

Attachments:

GoogleCodeExporter commented 8 years ago
This proposal isn't quite complete:

It's sufficient to replace 

Line ~162

    input.focus(function () {
        if ($(this).hasClass("search_init")) {
            $(this).removeClass("search_init");
            this.value = "";
        }
    });
    input.blur(function () {
        if (this.value == "") {
            $(this).addClass("search_init");
            this.value = asInitVals[index];
        }
    });

with

    if (Modernizr.input.placeholder) {
        input.attr("value","");  //delete value attribute to show placeholder
        input.attr("placeholder", asInitVals[index]);
    } else {
        input.focus(function () {
            if ($(this).hasClass("search_init")) {
                $(this).removeClass("search_init");
                this.value = "";
            } 
        });
        input.blur(function () {
            if (this.value == "") {
                $(this).addClass("search_init");
                this.value = asInitVals[index];
            }
        });
    }

Original comment by laubsau...@gmail.com on 8 May 2013 at 6:15