Client Script g_form.addOption working on Catalog Item, but not in Requested Item

mozarstein
Kilo Contributor

Hello,

 

I have a client script which on the fly adds an option to a select box.

It works fine in the catalog item, but when the item is requested and I see it on the requested items, the option is not there. The scripts executes, but the

g_form.addOption doesn't. The variable I am trying to add an option is defined in a variable set. Of course, the script has the indication to be executed in the catalog item and in the item request.

 

Thanks for your help!

5 REPLIES 5

Keith Mills
Giga Guru

There is a bug in g_form.getControl("fieldname") in task or RITM level so that it cannot manipulate drop down lists. We found a way to get the element ID for the variable and use strike javascript to add or clear the options. The following is the code. Hope it's helpful.   (Credit also goes to Terence Chan who worked with me to figure this out)


function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
  return;
}

var handler = g_form.getPrefixHandler('v_dropdown');
var map = handler.handlerObject.nameMap;
var id;
for (i = 0; i < map.length; i++){
  var name = map[i].prettyName;
  if (name == 'v_dropdown')
  id = map[i].realName;
}

var elem = g_form.getElement(id);

if (newValue == 'even'){
  clearOptions(elem);
  addOption(elem, 't1', 'Text1');
  addOption(elem, 't2', 'Text2');
}

}

function clearOptions(select) {
while (select.length > 0) {
  select.remove(select.length-1);
}
}