Support for HTML 5 placeholder attribute

Jim Coyne
Kilo Patron

I've created a function to add support for the HTML placeholder attribute. You can use it to include some extra helpful text in input fields:

find_real_file.png

It's real simple to use - just include a call to the function in an onLoad script with the name of the field/variable and the text you want displayed:



u_addPlaceholderAttribute('short_description', 'Enter a short description of the problem');

I've tested it in Chrome, Firefox and Opera on Windows 7 and it works. Of course it does not work in current version of IE, but it does work in the upcoming IE 10.

Here's the script:


function u_addPlaceholderAttribute(variableName, hint) {
  try{
      var fieldName = g_form.getControl(variableName).name.toString();
      if (Prototype.Browser.IE) {
          fieldName.placeholder = hint;
      } else {
          $(fieldName).writeAttribute('placeholder', hint);
      }
  } catch(err) {}
}

I've also attached it as an XML export of the function - just remove the ".txt" extension and import it into your instance.

1 ACCEPTED SOLUTION

Jim Coyne
Kilo Patron

Just setting this answer as correct as the actual thread was not meant as a question and it cannot be changed because it came from the original Community site.


View solution in original post

44 REPLIES 44

If I have to apply placeholder for multiple fields, what to write in the UI script?

hint = getMessage(hint);
saving the hint in UI messages

Now suppose, I have 5 Fields on the form having different messages and I want to call these messages from UI messages , what changes do I need to do in the UI Script?

Jim Coyne
Kilo Patron

Just setting this answer as correct as the actual thread was not meant as a question and it cannot be changed because it came from the original Community site.


Hi Jim, would you be able to offer some assistance with putting this placeholder text on a catalog variable? When I create a new onLoad client script against a catalog variable, it takes me to the variables table, but there is nowhere to select which variable to run the script against?



I have tried putting the first input as the variable name, but I'm not seeing the placeholder text in the cat item variable. All help is greatly appreciated.


What version is your instance on?   Can you include a screenshot of your current Client Script?   Have you created the "u_addPlaceholderAttribute" Script Include?


Here is the script include Jim,


find_real_file.png



I am still not seeing it in the catalog item. Below is the image of my client script on the catalog item table, I have also tried it on the variable table as well. Thanks for your help with this.



find_real_file.png