Add placeholder text in <g:ui_reference> field on a UI Page.

xiaix
Tera Guru

ScreenShot031.png

Since this won't work:   <g:ui_reference name="QUERY:u_locationISNOTEMPTY" table="u_bcp_sites" placeholder="Choose a site..." />

One must get crafty.   This will do the trick:

First, the jelly portion:

<?xml version="1.0" encoding="utf-8" ?>

<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

  <script>

  addLateLoadEvent(function(){

  setPlaceholderText();

  });

  </script>

  ...

  ...

Now the Client Script portion:

function setPlaceholderText()

{

  var el = gel('sys_display.QUERY:u_locationISNOTEMPTY');

  if (el)

  el.placeholder = "Choose a site...";

}

Even though I got this to work, is this the only way to get placeholder text in a <g:ui_reference> field on a UI Page ?

4 REPLIES 4

Brad Tilton
ServiceNow Employee
ServiceNow Employee

I don't think that ui_reference macro supports a placeholder attribute being passed to it, so I think the client script is really your only option.


Hi Brad Tilton,


How to put place holder on custom field through clientscript..??Any script??


amlanpal
Kilo Sage

Hi david,



Please find this helpful thread in your case: Support for HTML 5 placeholder attribute



I hope this helps.Please mark correct/helpful based on impact


Shiva Thomas
Kilo Sage

Great news, I've heard that HTML Placeholder will be supported natively in Jakarta!


I've written a blog article on the subject: Great UX Trick: HTML Placeholders