How can I access a radio button group option using CAF javascript API in order to disable it?
In my use case I have a Radio Button Group named gdnRadio and an option with id selectItemNativo and I’m calling this javascript:
On run-time this fails to execute because the CAF model returns null.
I noticed that the caf:cid(…) resolves to an id, but it doesn’t seem to be the proper one:
This is the value it resolves to: jsfwmp17615:importTemplate:importTemplateNumbering:numberingForm:selectItemNativo
This is the option element id on the HTML: jsfwmp17615:importTemplate:importTemplateNumbering:numberingForm:gdnRadio:7397
var radioGroupModel = CAF.model("#{caf:cid('gdnRadio')}");
var item = radioGroupModel.get('selectItemNativo');
var itemModel = CAF.model(item);
itemModel.setDisabled(true);
It is recommended that you use a “Disableable Panel” as a parent of the components you are trying to enable/disable, and use the javascript calls on this panel.
Strange, I thought that worked when I tried it. Which version of MWS (and fix level) are you using?
Another option would be to lookup the index of the item and then get it by index like this:
var radioGroupModel = CAF.model("#{caf:cid('gdnRadio')}");
var itemIndex = radioGroupModel.indexOf('selectItemNativo');
if (itemIndex == -1) {
alert("item not found");
} else {
var item = radioGroupModel.get(itemIndex);
var itemModel = CAF.model(item);
itemModel.setDisabled(true);
}
Or if you just want to list what the values of all the items in the radio group are you could do this:
var radioGroupModel = CAF.model("#{caf:cid('gdnRadio')}");
var itemList = radioGroupModel.list();
for (var i=0; i < itemList.length; i++) {
var item = itemList[i];
alert("item #" + i + " value is: " + item.getValue());
}