Easy way to make all fields readonly?

Home Forums Classic DFFS Easy way to make all fields readonly?

Viewing 19 reply threads
  • Author
    Posts
    • #20774
      Keith Hudson
      Participant

        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?

      • #20799
        Alexander Bautz
        Keymaster

          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

        • #27829
          Anne Maki
          Participant

            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,
            Anne

          • #27833
            Alexander Bautz
            Keymaster

              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

            • #28810
              AKOM
              Participant

                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.

              • #28830
                Alexander Bautz
                Keymaster

                  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

                • #37743
                  Rad
                  Participant

                    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.
                  • #37745
                    Rad
                    Participant

                      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 */
                      }

                    • #37746
                      Rad
                      Participant

                        tried using wrapChoiceField function as well but it doesn’t work with setTabToReadOnly fucntion.

                      • #37747
                        Alexander Bautz
                        Keymaster

                          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

                        • #37748
                          Rad
                          Participant

                            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.

                          • #37752
                            Alexander Bautz
                            Keymaster

                              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

                            • #37754
                              Rad
                              Participant

                                I’ve Dynamic Forms for SharePoint v4.4.5.43 – March 27, 2022

                              • #37755
                                Rad
                                Participant

                                  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.html

                                  Attachments:
                                • #37757
                                  Alexander Bautz
                                  Keymaster

                                    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

                                  • #37758
                                    Rad
                                    Participant

                                      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.
                                    • #37760
                                      Rad
                                      Participant

                                        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;
                                        });
                                        }
                                        });

                                        }

                                        • #37761
                                          Alexander Bautz
                                          Keymaster

                                            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

                                        • #37762
                                          Rad
                                          Participant

                                            perfect!

                                          • #37769
                                            Rad
                                            Participant

                                              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?

                                            • #37770
                                              Rad
                                              Participant

                                                Please ignore this question, found a solution.

                                            Viewing 19 reply threads
                                            • You must be logged in to reply to this topic.