Setting value of a Radio Button Group Client Side - xpages

I need to set the value of a Radio Button Group that has two possible values. I'm able to accomplish this with SSJS, but having issues setting it via CSJS. Any help is appreciated.

I use something like this:
function setRadioValue(value)
{
var elements = document.getElementsByName ("#{id:radioGroup1}");
for(i=0;i<elements.length;i++) {
if (elements[i].value == value) {
elements[i].checked = true;
}
}
}
Then you can just call setRadioValue("This is teh value of the Radio Button I want to set")
Thanks

You need to get the the server-side generated name of the radio button group using the #{id:} method. Example:
var radioButtonGroup = XSP.getElementById("#{id:radioButtonGroupName}");
You can then use client-side Javascript to manipulate the radioButtonGroup element. I believe you need to loop over the radio buttons in the elements until you find the radio button with the desired value. You can then set its checked value to true.

Related

Suitescript 2.0 Get Button on a sublist

I have an older Suitescript 1.0 user event script where on the BeforeLoad I change a label on a button in a sublist. (note this is a button on the sublist not on the main header of the form
In order to do that I did something like this:
function changePackageContentsButtonLabel(type, form, request)
{
var mySublist = form.getSubList('recmachcustrecord_tst_my_sublist');
if(mySublist != null)
{
var NewButton = mySublist .getButton('newrecrecmachcustrecord_tst_my_sublist');
if(NewButton != null)
{
NewButton .setLabel('New Label Text');
}
}
}
that worked fine in that i could find the button based on a call to the sublist.getButton
In 2.0 I was wondering how to do that.
I had thought i would call the getButton that is based off the context.form but it does not seem to find the button in that case. And though there are methods to addButton on a sublist, there does not appear to be a getButton on it. I know i could use JQuery but that may be a bit more brittle it seems.
In the Netsuite help section search for
SuiteScript 1.0 to SuiteScript 2.0 API Map
After you get the button object, use label property to get or set a value for the button label.
var myButton = form.getButton({
id : 'buttonid'
});
myButton.label = "New Label Text"
I ended up having to put the logic I wanted into a client script and called it off of the pageInit. What I had to do was use native javascript and locate the button (by document.ElementById() and when i got that element I was able to change the value. This was not the desired way but it seems that 2.0 does not allow you to locate a button on a sublist like 1.0 did.

I am having trouble with writing ScriptRunner Behaviours

I am trying to set two behaviors, but it is very hard because I do not have any coding background. The idea is that the ticket creation screen would hide/show fields depending on what the user chooses.
So the first behavior should be from a dropdown menu with 3 options (SAP, Jira, Other) and the dropdown menu's name is Affected Software. If the user chooses SAP, a textfield to appear which is called Transaction number. If they choose other, another textfield should appear called Please enter software name and otherwise, these should be hidden and not show any other fields.
Here is the code I tried to write:
import com.onresolve.jira.groovy.user.FormField
FormField dropDown = getFieldByName("Affected Software")
FormField other = getFieldByName("Transaction Number")
FormField other = getFieldByName("Please enter software name")
if (dropdown.getFormValue() == 'SAP') {
other.setHidden(false)
other.setFormValue("SAP chosen")
} if else (dropdown.getFormValue() == "Other")
other.setHidden(false)
other.setFormValue("Other chosen")
else {
other.setHidden(true)
}
The second behavior is a bit simpler. There is again a dropdown field called Is there a workaround with these options(yes, no, I don't know). If the user chooses yes, a field should show up called Explain the workaround. Otherwise nothing should change.
This is the code I tried to write for that one
import com.onresolve.jira.groovy.user.FormField
FormField dropDown = getFieldByName("Is there a workaround?")
FormField other = getFieldByName("Explain the workaround")
if (dropdown.getFormValue() == 'yes') {
other.setHidden(false)
other.setFormValue("yes chosen")
} else {
other.setHidden(true)
}
Could you please let me know what I am doing wrong? Thank you in advance!
I think you are looking for getValue() rather then getFormValue() as this will give you the ID of the underlying value, like an option ID.

Conditional validation not working for one field

I've 4 fields as shown below:
radioGroup1 is required if comboBox2 value and radioGroup4 & radio1 are blank. The validation message is suppose to go away if only one of 3 radio's is selected
If I select radioGroup1 or radio1 and update page, the validation message does not display.
If I select radioGroup4 and update page, the validation message is still displayed.
Here is a screen shot:
Here is a validation code for radioGroup1:
var comboBox2:com.ibm.xsp.component.xp.XspSelectOneMenu = getComponent("comboBox2");
var radio1:com.ibm.xsp.component.xp.XspInputRadio = getComponent("radio1");
var radioGroup4:com.ibm.xsp.component.xp.XspSelectOneRadio = getComponent("radioGroup4");
var radioGroup3:com.ibm.xsp.component.xp.XspSelectOneRadio = getComponent("radioGroup3");
if(comboBox2.getValue()!==''){
if(radioGroup3.getValue()==null){
if(radioGroup4.getValue()==null && radio1.getValueAsString()==''){
return true;
}else {
return false;
}
}
}
In second image there is a computed field capturing value of radioGroup4.
What am I doing wrong? When page is refreshed, radioGroup4.getValue() works in computed field but not in the validation script for radioGroup3.
When any one of 3 radio control selected, the other two are disabled thru script and it is working without any issue.
Resolved this issue as follows:
radioGroup4 was executing script and doing full update in the onChange event. Changed it to onClick event
It need two clicks in the radioGroup4 and required message for radioGroup3 vanishes.
This is not a perfect solution but I've to leave with it until I found perfect one.

How do I compute the Selected property of a BasicLeafNode for a Dynamic Content Control - Updated 03/26/2014

I have created an XPage with the following: Started by creating a custom layout control using the Application Layout. I aded the layout control to the xpage and then dropped in a Dynamic Content Control. I configured the control as follows:
<xe:dynamicContent id="dynamicContent1" defaultFacet="GovernanceReviews"
useHash="true">
<xp:this.facets>
<xc:ccViewDocumentTemplates xp:key="DocumentTemplates"></xc:ccViewDocumentTemplates>
<xc:ccViewGovProcurementReviews xp:key="GovProcurementReviews"></xc:ccViewGovProcurementReviews>
<xc:ccViewGovRevReporting xp:key="GovRevReporting"></xc:ccViewGovRevReporting>
<xc:ccViewGovRevWOCompleted xp:key="GovRevWOCompleted"></xc:ccViewGovRevWOCompleted>
<xc:ccViewGovernanceReviews xp:key="GovernanceReviews"></xc:ccViewGovernanceReviews>
<xc:ccViewProfilesByType xp:key="ProfilesByType"></xc:ccViewProfilesByType>
<xc:ccViewProfilesWithTargetCompl xp:key="ProfilesWithTargetCompl"></xc:ccViewProfilesWithTargetCompl>
<xc:ccViewLastUpdated xp:key="LastUpdated"></xc:ccViewLastUpdated>
<xc:ccViewUserGuide xp:key="UserGuide"></xc:ccViewUserGuide>
<xc:ccViewTracking xp:key="Tracking"></xc:ccViewTracking>
</xp:this.facets>
</xe:dynamicContent>
Then I dropped in a navigator control in the left column and created BasicLeafNodes to correspond to the dynamic content control I used the href property and used the #content="" to display the correct content.
This works just fine, but I am having problems figuring out how to make the selections in the navigator highlight when they are selected. I know I need to compute the Selectd property,but I can't figure out how to get the xp:key value so I can compare it to the SubmitValue. I know this is probably something simple, but I can't figure it out.
Can someone please enlighten me.
Thanks,
MJ
ADDED 03/26/2014 - I have a feeling that it has something to do with Using the href property of the Dynamic Content Control to perform the content switching. I know that makes the BasicLeafNodes Links. So, not sure how the Navigator records which link is being executed and how to capture that.
MJ
Add a value is the submitValue property
And in the onItemClick Event
Assign the submitted value to a viewScope variable
viewScope.Selected=context.getSubmittedValue()
And finally check if the viewScope variable equals your item submit value in the selected property. This needs to be calculated
if(viewScope.Selected="byCategory"){
return true
}else{
return false
}
The following is working for me:
if(viewScope.Selected == "byCategory"){
return true
} else{
return false
}
An equality test must be made with two equal symbols (or three). One equal symbol evidently always returns true.
I did it by jQuery. Just put the following code to the custom control, which contains navigator.
$( function() {
if (window.location.hash.length > 0) {
select()
}
});
$(window).on('hashchange', function() {
select();
});
function select() {
$(".lotusColLeft .lotusMenu .lotusBottomCorner li").removeClass(
"lotusSelected")
$(".lotusColLeft .lotusMenu .lotusBottomCorner li a")
.filter(
function() {
return window.location.hash.indexOf($(this).attr(
'href')) > -1
}).parent().addClass("lotusSelected")
}

CKEditor dialogs: referencing input fields by ID

Each input field in the CKEditor dialogs are renamed with a unique number, but the number changes depending on what options are visible.
I need to reference 'txtUrl' which has an id something like #35_textInput.
So far I have discovered that something like this should work:
alert(CKEDITOR.instances.myElement.document.$.body.getId('txtUrl'));
But it doesn't. Please help.
#Rio, your solution was really close! This was the final solution:
var dialog = CKEDITOR.dialog.getCurrent();
dialog.setValueof('info','txtUrl',"http://google.com");
return false;
var dialog = this.getDialog();
var elem = dialog.getContentElement('info','txtUrl');
within an onchange part of an element I now use
dialog = this.getDialog();
alert(dialog.getContentElement('info', 'grootte').getInputElement().$.id);
and it gives 'cke_117_select' as a result. (It's a selectbox)
alert(dialog.getContentElement('info', 'txtUrl').getInputElement().$.id);
gives 'cke_107_textInput'.
I think this is what you (or other visitors to this page) are looking for.
SetValueOf still doesn't provide the id, which you may need if you want to do more than fill a text field with a certain text.

Resources