Using a plugin such as watermark.js for adding the greyed out hint text in the search field of the Jquery datatable is not an option, I have to custom write it. I am almost there but facing this minor and strange issue explained below the following code snippet.
function toggleHintText()
{
// alert("The hint text should show up");
var textSuggest = "Please input search parameter";
var searchField = $('input:text');
searchField .attr("value", textSuggest );
searchField .addClass("activeHint");
searchField .focus(function() {
if(searchField .attr("value") == textSuggest)
{
searchField .attr("value", "");
}
});
searchField .keyup(function() {
if(searchField .attr("value") == "")
{
searchField .addClass("activeHint");
}
else
{
searchField .removeClass("activeHint");
}
});
searchField .blur(function() {
if(searchField .attr("value") == "")
{
searchField .attr("value", hinttext);
searchField .addClass("activeHint");
}
});
}
This method is called onload as below
$(document).ready(function() {
populateTableData();
toggleHintText();
} );
===========================================================================================
The issue I am facing is that without the alert that I have in the beginning of the method, the hint text doesn't show up in the search box. Does the alert some how work in favor of document.ready ? Does calling two methods from document.ready mess up the toggleHint method ?. One of my requirements is to preserve the user input search text if he clicks on the table row after search query and then hits the a custom back button, that is why I have to call it from document.ready.
Please advise and thanks in advance.