How can i Modify the Label of Form Fields With Client Scripts

nysbigdave
Kilo Expert

Hey Guys I am attempting to rewrite the label if a user has itil role..
however I believe the syntax maybe off.. can you help?


the field name is called u_comments

 

 

function onLoad() {
  if (!g_user.hasRole("itil"))
return;

var field = 'u_comments';
var fieldFormName = g_form.getTableName() + "." + field;
var fieldLabelName = "label." + fieldFormName;
var ctrl = $(fieldLabelName);
  if (!ctrl)
  return;
  var label = ctrl.select('label')[0];
  if (!label)
  return;
  var s = label.innerHTML;
  label.innerHTML = s.substring(0, s.length — 1) + ' (' + getMessage('Customer visible') + '):';
  //label.setStyle({fontWeight:"bold"});
}

1 ACCEPTED SOLUTION

nysbigdave
Kilo Expert

Mark Stanger (Crossfuze) Resolved this for me



function onLoad() {
      if(!g_user.hasRole('itil'))
              return;



      //Change the description label to 'My New Label' with bold red text
      changeFieldLabel('u_comments', 'My New Label', 'red', 'bold');
}



function changeFieldLabel(field, label, color, weight){
      try{
            var labelElement = $('label.' +   g_form.getControl(field).id);
            labelElement.select('label').each(function(elmt) {
                  elmt.innerHTML = label + ':';
            });
            if(color)
                  labelElement.style.color = color;
            if(weight)
            labelElement.style.fontWeight = weight;
      }catch(e){};
}


View solution in original post

11 REPLIES 11

Thanks Chuck ,



I will search for another alternative as this is a project requirement.


Aastha,



Sometimes you need to push back on requirements when you recognize risk is involved. Let the decision makers determine whether the cost of implementing a customized solution that carries risk of upgrade issues is worth it. They would rather know this now and decide that a few colors are not worth it than find out later and you get blamed for having known this information and not sharing it. Be sure the risk and documented decision is documented somewhere also.



(30+ years of IT has taught me a few lessons.)