Expand my Community achievements bar.

SOLVED

LOCK the form once its SAVEd?

Avatar

Level 8

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

1 Accepted Solution

Avatar

Correct answer by
Level 10

Then you should use the postSave event.

View solution in original post

15 Replies

Avatar

Level 8

Thank you, well. that squite long thread and seems original poster requirement also different (LOCK fields on CLICK of a BUTTON)

My requirement is just LOCK / GREY out all the fields of my_form as soon as user SAVEs the form local achine (no button will come into picture), so, do you think can i put the below code in PRE-SAVE event like below,

Pls. suggest me

Thank you

Avatar

Level 10

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

Avatar

Level 8

Thank you, perfect, but small problem.

Say, user started entering the data on my_form (but, not completed all the fields), user want to SAVE it once in the middle, hence pressed SAVE button, so, your suggested code triggered and copy saved on PC, well.

When user checked that SAVEed copy on PC, fields are LOCKed, well, perfect.

But, user want to back to the work-in-progress form and want to fill the rest of the fields, but with our code all work-in-progress form also preotected/locked!!

So, i guess, i can repeate your with "open" right? as below

Pls. let me know

1) is it OK right? "open" is correct right?

2) I guess, i must put this open code in POST-SAVE event (postSave) right?

any suggestions pls?

Thank you

Avatar

Level 10

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

}

Avatar

Level 8

Thank you.

My impression:

PreSave: Fires as soon as user clicks the SAVE button, but not YET the form saved on PC

PostSave: Fires, AFTER form is saved on PC

Not sure, did i understood correctly or not

http://help.adobe.com/en_US/livecycle/9.0/designerHelp/index.htm?content=000753.html

I will explain my requirement:

My form uses by 2 kind of user groups, say, grp_1 and grp_2 (i knew/ my_form knows that which group is logged-in/accessing/opened the form, so that i can differentiate the below 2 scenarios easily, no worries here for this validation )

grp_1: With your first code snippet working well, i am all set here, Thank you

grp_2: User opens the form, starts entering data, user is half way, want to take coffee braek, hence want to SAVE at that point as is on PC, so user clicked SAVE button of the form (work-in-progress) and the form has saved on PC...........if user opens this saved form, it must be locked status/not editable status

Well,

User came back from coffee, want to continue filling the rest of the stuff/fields/pages of the form, so, let user go ahead filling the form......may be if user want to save any time (even completing all the fields/sections/pages) the form on PC, let SAVE, but again the the SAVEd form should ALWAYS in lock/non-editable state

Pls. help, where should i write the JS for this grp_2 case, JS Code snippet pls?

I guess, i need to write some piece in PreSave (as i am doing for grp_1) and fields "open" peice is in docClose or Validate event as below link tells, not sure

http://help.adobe.com/en_US/livecycle/9.0/designerHelp/index.htm?content=000753.html

Than you

Avatar

Level 10

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

}

Avatar

Level 8

Thank you, with the below code

whats the issue happening is,

grp_2: User opens the form, starts entering data, user is half way, want to take coffee braek, hence want to SAVE at that point as is on PC, so user clicked SAVE button of the form (work-in-progress) and the form has saved on PC...........if user opens this saved form, it must be locked status/not editable status,

Avatar

Level 10

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?

Avatar

Level 8

Agreed, but Sorry to say that, my company is not OK for putting this button.

OK, just in nustshell,

Currrently am fine with LOCKing of the my_form, which is SAVEd on my PC, well.

Now, just i want only one thing: Let the user continue filling the work-in-progress opened form on the browser, keep open these fields for user so that user enters the data, so i need.....Pls. let me know Which evets fires after saving the form on PC so that i will keep your suggested "open" JS on that form so that the user can continue filling

Thank you

Avatar

Correct answer by
Level 10

Then you should use the postSave event.