Absent Member.
Absent Member.
6065 views

Is there a way to hide unchecked checkboxes from a multi-relational field?

Jump to solution
Hello,

I have a multi-relational field that I'm displaying as checkboxes.

If I select 2 out of 4 in a transition only those two will display on the State form.

If I use another transition to update the field all four checkboxes will show. I only want the two that are selected to show similar to the way its displaying on the state form.

Is there some javascript that will enable me to do this?

Regards,

Will
0 Likes
1 Solution

Accepted Solutions
Absent Member.
Absent Member.
Will,

See if this helps.

1. In the form properties in Composer on the Javascript tab make sure the JQuery box is checked.
2. Try this line instead from the original code.
$(":[value='"+ x.value +"']").hide();

In troubleshooting just use this code and see what the alert says

var x = $(GetFieldWidgetByName("PENDING_LOWER_ENVIRONMENTS")).find(":checkbox:not(:checked)")
alert(x);

View solution in original post

0 Likes
8 Replies
Absent Member.
Absent Member.
Will,

Is the goal to have the existing values still selectable when you do the update? Like instead of 4 options to pick from now you only have the two selected options selectable so you could essentially unselect only from the original selected ones?

I'm assuming that's the case or else you could just make the field read only on the update and it would look like the state form.

If it is the first option above that would take some clever javascript to do but take a look at doing it with jquery and using the .remove() function
0 Likes
Absent Member.
Absent Member.
Brian,

Yes, you are correct. I still want the remaining items selectable during the transition. I'm doing a variation on the old Voting sample that was included in Teamtrack. It's for developers installing into different environments. As they install items from the Initially Selected list the items go into the Installed list. They may not want to install all at once. That's working fine...

1)Users initially select the environments they want their release to go into.

2) The Next state view only shows the environments they have selected (So, the functionality I want works by default in the state view).

3) On an install Transition the checkboxes originally selected show up along with all the items from the Initial list, those that were selected and those that were not selected. I don't want the unselected items.

It works but it's a little confusing when checkboxes that should not be in the equation show up.

I'll try your recommendations. Thanks.

Regards,

Will
Absent Member.
Absent Member.
Will,

Give this a try.

Create a form action that fires on load. and have it run a javascript. Put the following in

var x = $(GetFieldWidgetByName("MyMulti")).find(":checkbox:not(:checked)")

for (i = 0; i < x.length; i++) {
$(":[title='"+ x.title +"']").hide();
}


You may have to add a "\" to part of the code depending on the version of SBM but you will know as you will get a yellow indicator in the javascript screen.

In the code substitute your multi relational field name where mine is MyMulti

It's not the most glamorous because all it does is removes the checkboxes but due to the way we coded the multi select boxes it's difficult to get rid of all the artifacts. (See attachment )

Hope it helps
Brian
0 Likes
Absent Member.
Absent Member.
I've tried the code within the Action. Running the Debugger I get "SCRIPT5007: Object expected". I know the javascript is getting picked up, its bombing out. I tried a message box in the javascript and that's getting invoked. It just does not like the code. I've tried the display name "Pending Lower Environments" and the Database name "PENDING_LOWER_ENVIRONMENTS". No difference.

Not sure where to place the / you recommended.


var x = $(GetFieldWidgetByName("PENDING_LOWER_ENVIRONMENTS")).find(":checkbox:not(:checked)")
for (i = 0; i < x.length; i++)
{
$(":[title='"+ x.title +"']").hide();

}
0 Likes
Absent Member.
Absent Member.
Will,

See if this helps.

1. In the form properties in Composer on the Javascript tab make sure the JQuery box is checked.
2. Try this line instead from the original code.
$(":[value='"+ x.value +"']").hide();

In troubleshooting just use this code and see what the alert says

var x = $(GetFieldWidgetByName("PENDING_LOWER_ENVIRONMENTS")).find(":checkbox:not(:checked)")
alert(x);

View solution in original post

0 Likes
Absent Member.
Absent Member.
OK, finally got it to work. Problem was that I did not have the "JQuery" box checked off. Once checked and published, the project worked fine.

Brian, thanks again for your help.

Regards,

Will
0 Likes
Absent Member.
Absent Member.
Now one more request on this topic.... A big twist. It's working and only showing the checked boxes... Now, what I would to do is once the checked boxes are showing I would like to uncheck them..... So, final display will show available checked boxes without their check marks... Or, possibly a button on the form that would "Un Check" all selections.
0 Likes
Absent Member.
Absent Member.
This worked for unchecking the multi-relational field. I removed the javascript from the field action within the field and placed it into a javascript file within the forms javascripts dropdown property. I was not able to set a breakpoint when the javascript was within the field action.



if (transition_value_var == "DESKTOP_ENVIRONMENT.REMOVE")
{

if (GetFieldWidgetByName) {
var x = $(GetFieldWidgetByName("REJECTED_LOWER_ENVIRONMENT")).find(":checkbox(:checked)"); for (i = 0; i < x.length; i++)
{
var y = x.checked
var z = x.value // Do I even need z in this code....?
if ( y == true )
{
$(":[value='"+ x.value +"']").attr("checked",false); }
else
{
$(":[value='"+ x.value +"']").hide(); //Makes the checked items read only.
}
}
}
}
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.