Skip to main content

Is it possible to determine which was the latest checked item in the checbox list?

 

We have a requirement where the user selects few items in the checkbox list (each item represents an attachment) and saves the form. At a later stage they might open the form and chose to add another item from the checkbox list to the selection. When the latest item is selected, it should trigger a subform and pass the name of the document into it.

e.g.

Checkbox list contains Chec1, Check2, Check3, Check4. I select Check1 and Check2 and save the form. I then go back into the saved form and on load event the checkbox list is populated with Check1 and Check2 selected. I then check Check3 and want to only pass Check3 value into a subform. Currently, I am only able to retrieve all the selected values, not the last one.

 

Is this possible?

 

 

Hi thompsle,


The problem is the checkbox sorts the checked values, so the last value in the string (i.e. Check1;Check2;Check5;) will not be always right.
You will need JavaScript to achieve this.


 


Please find steps below:


 


1- Add 4 Data labels controls with the following names:


 


a- dlOldValue
b- dlNewValue
c- dlDifference
d- dlScript (check property 'Literal')


 


 


2- Add rule 'When Choice is Changed'


 


 


3- Add 3 'Transfer Data' action in the following order:


 


- Transfer the Choice control to dlNewValue
- Transfer The following script to the dlScript


 


<script type="text/javascript">$(document).ready(function(){

var array1 = $("[name='dlOldValue']").text().split(';');
var array2 = $("[name='dlNewValue']").text().split(';');
var difference = [];
jQuery.grep(array2, function(el) {
if (jQuery.inArray(el, array1) == -1) difference.push(el);
});
$("[name='dlDifference']").SFCLabel('option', 'text', difference);
});


- Transfer the Choice control to dlOldValue and clear the dlScript


 


The script will find the difference between the old value and the new value then transfer it to the dlDifference control
There are other ways to implement this and maybe shorter if you modify some bits in the script.


 


Let me know if I misunderstood the requirements
Hope that helps


Reply