Permission Trimmed Choice Field

Forums Classic DFFS Permission Trimmed Choice Field

Viewing 4 reply threads
  • Author
    Posts
    • #15993
      DerekH
      Participant

      Alexander,
      Does DFFS support permission trimmed choice fields? If not, can it be created?

      I have a situation where I have a choice field with 23 options. I want to present just a few of these choices to a person logged in based on their permission group.

      It can be administered so that you specify which permission groups can see each choice in a choice field. Is this possible?

      Example:
      Person in Group #1: Choices 1, 2, 3 & 4
      Person in Group #7: Choices 4, 5, 6 & 7
      Person in Group #3: Choices 6 & 7
      Person in Group #6: Choice 8
      Person in Group #5: Choice 9, 10, 11, etc.
      etc.

      • This topic was modified 6 years, 11 months ago by DerekH.
    • #16044
      Alexander Bautz
      Keymaster

      You can use something like this:

      function trimOptionsByGroupMembership(){
      	var select = $("#dffs_ChoiceColumn1"), hide = function(arr){
      		$.each(arr, function(i, v) {
      			$(select).find("option").eq((v-1)).hide();
      		});
      	}
      	if(spjs.dffs.verifyGroupMembership("GroupA")){
      		hide([1,2,3]);
      		return;
      	}
      	if(spjs.dffs.verifyGroupMembership("GroupB")){
      		hide([4,5,6]);
      		return;
      	}
      }
      trimOptionsByGroupMembership();

      Change “ChoiceColumn1” to match your field name, and “GroupA” and “GroupB” to match your group names (you can use the number if you like also, but use quotes like “32”).

      The array in the hide function is the indexes that shall be hidden.

      Let me know how this works out,
      Alexander

    • #16057
      DCH
      Participant

      Alexander, this is awesome and simple. It worked for me with one slight change to the eq method. I also negated the if so the values were hidden unless you belonged to a specific group.

      function trimOptionsByGroupMembership(){
      	var select = $("#dffs_FeedbackType"), hide = function(arr){
      		$.each(arr, function(i, v) {
      			$(select).find("option").eq(v).hide();
      		});
      	}
      	if(!spjs.dffs.verifyGroupMembership("22")){
      		hide([3]);
      		return;
      	}
      }
      
      trimOptionsByGroupMembership();

      Also it doesn’t appear to work in IE. Still testing.

      Thanks!

      • This reply was modified 6 years, 11 months ago by DCH.
    • #16069
      Alexander Bautz
      Keymaster

      The reason for using (v-1) was to let the user treat the first option as 1 and not 0 as the eq-selector is 0-indexed.

      I tested it in IE and it doesn’t support hiding options so you must change it from hide() to remove()

      Alexander

    • #16262
      DerekH
      Participant

      Okay, after carving out some time to implement this solution, here’s what I have.

      Thanks Alexander and DCH for the additional comments, they were helpful. Since we primarily use IE, I changed both the variable ‘hide’ to remove and the .hide() to .remove() to keep the terms synchronized.

      My thoughts: Initially, I had a hard time understanding the array (since I’m illiterate in JavaScript), but after some trial and error, I figured out what was happening: Each time I removed an item from my list, the next item would take on that array number (e.g. #4), so rather than trying to remove 4,5,6…16,17 items, I had to remove the 4th array element each time–fourteen times in a row (see below code for group “75”. Once I had this figured out, it was off to the races!

      Thanks for the extremely useful solution!

      function trimOptionsByGroupMembership(){
      	var select = $("#dffs_Handoff"), remove = function(arr){
      		$.each(arr, function(i, v) {
      			$(select).find("option").eq((v-1)).remove();
      		});
      	}
      	if(spjs.dffs.verifyGroupMembership("75")){   // CoE BA Group
      		remove([3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,7]);
      		return;
      	}
      	if(spjs.dffs.verifyGroupMembership("76")){    // CoE BI Group
      		remove([1,1,5,5,5,5,5,5,5,5,5,5,5,5,5,8]);
      		return;
      	}
      	if(spjs.dffs.verifyGroupMembership("77")){    // CoE TAr Group
      		remove([1,1,2,2,2,4,4,4,4,4,5,5,5,5,5,6,6]);
      		return;
      	}
      	if(spjs.dffs.verifyGroupMembership("78")){    // CoE LM Group
      		remove([1,1,2,2,2,2,13,14,14]);
      		return;
      	}
      	if(spjs.dffs.verifyGroupMembership("79")){    // CoE TAn Group
      		remove([1,1,2,2,2,4,4,4,4,4,5,5,5,5,5,6,6]);
      		return;
      	}
      	if(spjs.dffs.verifyGroupMembership("323")){    // CoE Systems Group
      		remove([1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3]);
      		return;
      	}
      	if(spjs.dffs.verifyGroupMembership("329")){    // CoE Process Group
      		remove([1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3]);
      		return;
      	}
      }
      trimOptionsByGroupMembership();
      • This reply was modified 6 years, 11 months ago by DerekH.
      • This reply was modified 6 years, 11 months ago by DerekH.
Viewing 4 reply threads
  • You must be logged in to reply to this topic.