4 Replies Latest reply on Jan 26, 2015 9:37 AM by Magus069

    required fields with 'read only' on email submit.

    PeeMAC Level 1

      Hi folks.

       

      My hope is to lock fields down to read only when the required fields have had data entered.  These are both text fields and radio buttons.


      I currently have my fields set to user entered required on my form and an email submit set to submit as PDF.

       

      attached to my Email submit button is this;

      form1.#subform[0].EmailSubmitButton1::postSubmit:form - (JavaScript, client)

      for (var nPageCount = 0; nPageCount < xfa.host.numPages; nPageCount++) {

      var oFields = xfa.layout.pageContent(nPageCount, "field");

      var nNodesLength = oFields.length;

       

       

      for (var nNodeCount = 0; nNodeCount < nNodesLength; nNodeCount++) {

      oFields.item(nNodeCount).access = "readOnly";

      }

      }

       

      Previewing my form;

      Clicking submit without entering data to required fields will highlight those fields as expected but it also locks all fields down to read only, not allowing the user to enter data in to the required highlighted fields.

       

      I've done some research but got nowhere fast.  My thinking was, if the fields don't validate then don't run the above script else run the script and submit as PDF.

       

      I've little knowledge of scripting but I am keen to learn and will do.  I don't understand the language but do have an idea of how its structured.   I done a fair bit of basic programming maybe 10 years ago but its vague.

       

      Help is very much appreciated.

        • 1. Re: required fields with 'read only' on email submit.
          PeeMAC Level 1

          Have I placed this in the wrong section or are replies normally expected to take longer than a few days?

          • 2. Re: required fields with 'read only' on email submit.
            jnicholas330 Level 3

            You need to look into a two button solution. The first button will call the second, hidden submit button if the validation passes, which contains the lockdown code. Otherwise, the second button will not get called, and the form can be edited as before.

            • 4. Re: required fields with 'read only' on email submit.
              Magus069 Level 4

              Hi there,

              you can actually use a recursive method, if you haven't found anything that suits your request...

               

               

              *Sorry, modified the function, there was a few errors in the previous function I provided

              //rootObject is the rootNode(Subform) which contains all fields you want to change their access property to readOnly

               

              function setAccessFields(rootObject){

                   if (rootObject.nodes.length > 0 && !rootObject.isPropertySpecified("presence") || (rootObject.isPropertySpecified("presence") && rootObject.presence == "visible")){

                        if (rootObject.className != "field" && rootObject.className != "exclGroup"){

                             for (var i = 0; i < rootObject.nodes.length; i++){

                                  setAccessFields(rootObject.nodes.item(i));

                             }

                        } else if(rootObject.className == "field" || rootObject.className == "exclGroup"){

                             rootObject.access = "readOnly";

                        }

                   }

              }

               

              This will only set all visible fields to readOnly... But even if the fields are readOnly, their events can still be triggered.

              To avoid events to trigger even in readOnly, you can set their access property to "nonInteractive" instead of "readOnly"

               

              Hope this help!