Home › Forums › Classic DFFS › Easy way to make all fields readonly?
Tagged: readonly builtinFunctions
- This topic has 21 replies, 5 voices, and was last updated 5 months, 2 weeks ago by Alexander Bautz.
-
AuthorPosts
-
-
May 1, 2018 at 17:05 #20774
We are trying to rebuild some lists/forms that were created in another system (not SharePoint). In some cases, the forms have dozens and in a few cases even more than 50 sections, with complex rules for which fields are editable and which are readonly. We would like to be able to create a rule or function that turns all fields on the form readonly unless except for the fields on the tab that matches the current section being worked on. We anticipate using a separate tab for each section of the form, although that may be difficult for forms with over 50 sections.
A. Is there code we can use to make all fields read only? If so, we could create a rule for each tab on the form that makes all fields read only except for the tab currently being worked.
B. Any other ideas of how to simplify the creation of these very complex forms?
-
May 2, 2018 at 20:38 #20799
You can loop over all visible fields and set them readonly with this custom js snippet:
var arrToSetReadonly = []; jQuery.each(spjs.dffs.data.tabFieldsObj,function(fin,o){ arrToSetReadonly.push(fin); }); spjs.dffs.doReadOnly(arrToSetReadonly);
Then you can make the fields in the current tab editable like this:
var arrToSetEditable = []; jQuery.each(spjs.dffs.data.tabConfigObj[spjs.dffs.data.selectedTab].fields,function(i,fin){ arrToSetEditable.push(fin); }); spjs.dffs.undoReadOnly(arrToSetEditable);
See what you can do with this example code.
Regarding QB:
How many fields do you have in one of these forms? – If you have a large number of fields, your form might be a bit slow to handle – especially if you use an older version of IE. You might want to look into splitting the form into one “mother” and several “children” for example using vLookup.Best regards,
Alexander -
December 4, 2019 at 17:12 #27829
Hi Alex,
I had a similar question as Keith and tried to apply the solution you presented above. I put the “set to read only” steps within a function in the Custom JS and I call that function within a rule that runs when the form is loaded (edit mode). However, when testing, I get two error messages (see attachments) and the form fields still end up as editable.Any idea what could be happening?
Thanks,
AnneAttachments:
-
December 4, 2019 at 17:43 #27833
From the error message it looks like there may be a bug in your code. Try bringing up the developer console (hit F12 > Console) and try pasting and running the function there to see if it works. You will bet better error messages when you do it like that.
Alexander
-
February 24, 2020 at 15:46 #28810
Is there are easy way to set all invisible fields (fields that I have set to hide using “.hide” in my JS ) in a tab to clear out or empty them when form is saved?
i have tried this
$(“td[style$=’display: none;’]”).closest(‘tr’).find(“select”).each(function(i) {
alert($(this).prop(‘title’));
$(this).prop(‘selectedIndex’,’-1′);});
But it is picking all the selects boxes not just one where display: none. -
February 24, 2020 at 19:15 #28830
Not sure how your code looks, but if you have an array of the internal names of the fields you hide you can do it like this:
var arrOfHidden = ["FieldOne", "FieldTwo"]; jQuery.each(arrOfHidden, function(i, fin){ setFieldValue(fin, ""); });
Alexander
-
May 31, 2024 at 17:39 #37743
Hi, I am trying to use the below code to make all the fields in Tab0 (I’ve 2 tabs and one should be read only based on access level) read only and noticing couple of things:
1. it doesn’t seem to work for all the fields. Some fields still show as editable. What could be the issue?
2. The multiselect checkboxes all align in one column (using function multichoiceVertical -see below to align checkboxes horizontally) but calling setTabToReadOnly is removes the format
function setTabToReadOnly(tabIdx){
console.log(“function: setTabToReadOnly: ” + tabIdx);
var arrToSetReadonly = [];
jQuery.each(spjs.dffs.data.tabFieldsObj,function(fin,o){
// jQuery.each(spjs.dffs.data.tabConfigObj[tabIdx].fields,function(i,fin){arrToSetReadonly.push(fin);
});spjs.dffs.doReadOnly(arrToSetReadonly);
spjs.dffs.toggleSaveBtnByRule(false); /* hide save button */
}function multichoiceVertical(arr,breakAfter){
var toFind, index, counter, table;
toFind = “td.ms-formbody”;
if($(“td.ms-formbodysurvey”).length>0){
toFind = “td.ms-formbodysurvey”;
}
$.each(arr,function(i,fin){
if(fields[fin]!==undefined){
index = 0;
counter = 0;
table = $(fields[fin]).find(toFind+’ table:first’);
$(table).prepend(“<tr id=’vertical_”+fin+”_”+index+”‘></tr>”);
$(table).find(‘tr:first’).nextAll().each(function(){
if(counter%breakAfter===0){
$(“#vertical_”+fin+”_”+index).after(“<tr id=’vertical_”+fin+”_”+(index+1)+”‘></tr>”);
index += 1;
}
$(this).find(‘td:first’).appendTo($(“#vertical_”+fin+”_”+index));
$(this).remove();
counter += 1;
});
}
});
}- This reply was modified 5 months, 3 weeks ago by Rad.
-
May 31, 2024 at 17:55 #37745
using this :
function setTabToReadOnly(tabIdx){
console.log(“function: setTabToReadOnly: ” + tabIdx);
var arrToSetReadonly = [];
//jQuery.each(spjs.dffs.data.tabFieldsObj,function(fin,o){
jQuery.each(spjs.dffs.data.tabConfigObj[tabIdx].fields,function(i,fin){arrToSetReadonly.push(fin);
});spjs.dffs.doReadOnly(arrToSetReadonly);
spjs.dffs.toggleSaveBtnByRule(false); /* hide save button */
} -
May 31, 2024 at 19:26 #37746
tried using wrapChoiceField function as well but it doesn’t work with setTabToReadOnly fucntion.
-
May 31, 2024 at 22:01 #37747
I suggest you create a new rule that triggers on “No trigger (must be triggered manually)”. In this rule you add all the ReadOnly fields you want to set. Name the rule for example “DoAlotOfFieldsReadonly”
Now, in your Custom JS you call this rule like this to set all fields readonly:
spjs.dffs.triggerRule(["DoAlotOfFieldsReadonly"]);
Alexander
-
May 31, 2024 at 22:52 #37748
tried it and same results. Fr some reason the same 6 fields are not being set as read only. in addition the check boxes get aligned to one column.
-
June 1, 2024 at 09:58 #37752
What version of DFFS are you running? – it might be a bug in an older version.
If you are up to date, I think there might be interference from other rules – look at all rules that interacts with the same fields and see if you might need to change the “reversing” of rules that are not evaluated to true.
Alexander
-
June 3, 2024 at 17:02 #37754
I’ve Dynamic Forms for SharePoint v4.4.5.43 – March 27, 2022
-
June 3, 2024 at 20:39 #37755
Excuse my ignorance as I am new to DFFS and trying to catch up.
I am trying to upgrade to v4.4.5.51 and using a custom DFFS name located in a different path but the default DFFS file location appears within the content editor. How do I change the root path? Pls see attached screenshot.This is the message that appears within the content editor:
DFFS file location: /sites/TLP_Intake/SPJS/DFFS. The dffs_folder_location variable is set to “root”.Actual path of installer file:
/sites/TLP_Intake/DUA/SPJS/DFFS_v44551_20240428/installer/Installer_CEWP_code.htmlAttachments:
-
June 4, 2024 at 09:20 #37757
You basically just remove the contents of the /SPJS/DFFS folder and upload the contents of the zip-file you downloaded.
If your old installation was done using the “version 1 installer” you should update to V2 and then use the installer to uninstall and then reinstall DFFS to the forms.
The uninstall / reinstall will not affect your configurations – they are stored in a separate list in your site and will pop back when you reinstall.
Follow the instructions in the installation manual here: https://spjsblog.com/dffs/dffs-installation-manual/#Upgrading_from_a_previous_version
Alexander
-
June 4, 2024 at 15:18 #37758
thank you, I was able to install the latest version but the issue of some fields still showing in edit mode and the checkboxes losing their alignment still persists. I can confirm that there are no additional rule set for those fields.
- This reply was modified 5 months, 3 weeks ago by Rad.
-
June 4, 2024 at 21:17 #37760
I was able to achieve the desired functionality using rules. Thank you for the guidance. Only think left now is the multi choice checkbox alignment. In the read only mode, the checkboxes all align vertically. I’ve around 30 so need them to align some horizontally. I am using the below function and it works great in edit form but not when I set the field to readonly.
function multichoiceVertical(arr,breakAfter){
var toFind, index, counter, table;
toFind = “td.ms-formbody”;
if($(“td.ms-formbodysurvey”).length>0){
toFind = “td.ms-formbodysurvey”;
}
$.each(arr,function(i,fin){
if(fields[fin]!==undefined){
index = 0;
counter = 0;
table = $(fields[fin]).find(toFind+’ table:first’);
$(table).prepend(“<tr id=’vertical_”+fin+”_”+index+”‘></tr>”);
$(table).find(‘tr:first’).nextAll().each(function(){
if(counter%breakAfter===0){
$(“#vertical_”+fin+”_”+index).after(“<tr id=’vertical_”+fin+”_”+(index+1)+”‘></tr>”);
index += 1;
}
$(this).find(‘td:first’).appendTo($(“#vertical_”+fin+”_”+index));
$(this).remove();
counter += 1;
});
}
});}
-
June 5, 2024 at 15:56 #37761
Ah, now I understand. You must remove this function and use the setting in the Misc tab named “Multiple-choice columns (checkboxes and radio buttons) in multiple columns”.
Alexander
-
-
June 5, 2024 at 18:18 #37762
perfect!
-
June 5, 2024 at 20:23 #37769
Another q around multiselect checkboxes – Wondering if there’s already a built in functionality wherein if a checkbox is selected then rest of the boxes can be disabled?
-
June 6, 2024 at 05:48 #37770
Please ignore this question, found a solution.
-
June 6, 2024 at 16:45 #37771
I’m glad you figure it out.
Alexander
-
-
-
AuthorPosts
- You must be logged in to reply to this topic.