Skip navigation
Currently Being Moderated

LOCK the form once its SAVEd?

Jul 24, 2012 9:37 PM

Hello

 

I have developed a form, opening in browser, as online, well.

 

But, if user once SAVEs that form on local machine, all the field LOCKED or GREYED OUT, it shuld meant for just DISPLAY purpose

 

Pls. let me know hoe can i get this requirement, JS code snippet pls?

 

Thank you

 
Replies
  • Currently Being Moderated
    Jul 24, 2012 11:04 PM   in reply to srinivas1506
     
    |
    Mark as:
  • Currently Being Moderated
    Jul 25, 2012 12:12 PM   in reply to srinivas1506

    Well,

     

    you can use the preSave event, but you need to lock all fields.

    Here's a script that will look for all fields and lock them.

     

    function lockFields(vNode) { 
        if (vNode.className === "field") {
            vNode.access = "protected";
        } 
        for (var i = 0; i < vNode.nodes.length; i += 1) {
            lockFields(vNode.nodes.item(i));
        }
    } 
    lockFields(xfa.form);
    
     
    |
    Mark as:
  • Currently Being Moderated
    Jul 30, 2012 9:28 AM   in reply to srinivas1506

    Well,

     

    to open the fields, you just need to change the statement from "protected" into "open".

     

    function unlockFields(vNode) {
        if (vNode.className === "field") {
            vNode.access = "open";
        }
        for (var i = 0; i < vNode.nodes.length; i += 1) {
            unlockFields(vNode.nodes.item(i));
        }
    }
    unlockFields(xfa.form);
    

     

    But it makes no sense to put this script into the postSave event while also using the lockFields function in the preSave event.

    If you'll do so the form to be always editable, because the presSave event always happens after saving the form.

     

    So you should think about the scenarious that might happen in your form to find the suitable events and workflows.

    One could be to ask the users, if they want lock the form?

     

    function lockFields(vNode) {
        if (vNode.className === "field") {
            vNode.access = "protected";
        }
        for (var i = 0; i < vNode.nodes.length; i += 1) {
            lockFields(vNode.nodes.item(i));
        }
    }
     
     
    if (xfa.host.messageBox("Do you want to lock all the fields in the form?\n\nFurther changes aren't possible if you click 'Yes'!", "Lock form?", 2, 2) === 4) {
              lockFields(xfa.form);
    }
    
     
    |
    Mark as:
  • Currently Being Moderated
    Jul 31, 2012 9:15 AM   in reply to srinivas1506

    Hi,

     

    first, the preSave event occurs just before the PDF is saved, means if the save operation has not beed aborted by the user.

    Details can be found in the XFA specs.

     

    second, if you say you can determine which user group uses the form, then you can use my previous sample with an additional if expression.

     

    function lockFields(vNode) {
        if (vNode.className === "field") {
            vNode.access = "protected";
        }
        for (var i = 0; i < vNode.nodes.length; i += 1) {
            lockFields(vNode.nodes.item(i));
        }
    }
     
     
    if (here goes your expression to determine user group 2) { 
         if (xfa.host.messageBox("Do you want to lock all the fields in the form?\n\nFurther changes aren't possible if you click 'Yes'!", "Lock form?", 2, 2) === 4) {
              lockFields(xfa.form);
         }
    }
    
     
    |
    Mark as:
  • Currently Being Moderated
    Jul 31, 2012 11:25 AM   in reply to srinivas1506

    So, you can add a button to unlock those fields with that unlockFields script posted above.

    If you can determine the user group (as you said), then you also can control the visibility of that button, so only user group 2 can see it.

     

    But, those tricks often work poor, because users may change the creteria you use to determine their grouping or they find a work-around you did not think of before.

    The way users work is almost unpredictable, so you should always expect the unexpected.

     

    How do you separate your user groups at the moment?

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 31, 2012 12:17 PM   in reply to srinivas1506

    Then you should use the postSave event.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points