Expand my Community achievements bar.

SOLVED

Lock fields permanently

Avatar

Level 2

I need to lock all the fields in a form, after clicking a button.

I have used the following script, seen in the documentation, but when I save the form and reopen it, the fields are all again editable.

//Disabling all form fields
function disableAllFields() {
    // Get the field containers from each page.
    for (var nPageCount = 0; nPageCount < xfa.host.numPages; nPageCount++) {
        var oFields = xfa.layout.pageContent(nPageCount, "field");
        var nNodesLength = oFields.length;
        // Set the field property.
        for (var nNodeCount = 0; nNodeCount < nNodesLength; nNodeCount++) {
            oFields.item(nNodeCount).access = "readOnly";
        }
    }
}

How can disable permanently the fields?

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

My guess is that you are not saving the "state" of the form and it is being reset when you re-open the form. On the Form properties page undeer Defaults make sure that the radio button under the "Preserve Scripting changes to form when saved" is set to Automatically.

Paul

View solution in original post

2 Replies

Avatar

Correct answer by
Former Community Member

My guess is that you are not saving the "state" of the form and it is being reset when you re-open the form. On the Form properties page undeer Defaults make sure that the radio button under the "Preserve Scripting changes to form when saved" is set to Automatically.

Paul

Avatar

Level 6

Place one hidden checkbox and update the value (default is 0) to 1 on click of the button to execute disableAllFields() method.

While opening always check the value of the hidden check box and if the value is 1 make the form fields are readonly.

Also you can make simply topsubformname.access="readOnly" which will give the same as ur function.

But any case u can check with some hidden field value and achieve this.

RAGHU.

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----