Home › Forums › Classic DFFS › Permission Trimmed Choice Field
Tagged: Permission Trimmed Choice Field
- This topic has 4 replies, 3 voices, and was last updated 7 years, 7 months ago by DerekH.
-
AuthorPosts
-
-
March 6, 2017 at 16:53 #15993
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 7 years, 8 months ago by DerekH.
-
March 9, 2017 at 21:32 #16044
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 -
March 9, 2017 at 23:54 #16057
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 7 years, 8 months ago by DCH.
-
March 11, 2017 at 10:33 #16069
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
-
March 30, 2017 at 21:18 #16262
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();
-
-
AuthorPosts
- You must be logged in to reply to this topic.