Easy way to make all fields readonly?

Forums Classic DFFS Easy way to make all fields readonly?

Viewing 5 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

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