Skip to main content

Notifications

Make form read-only using JavaScript

Community Member Profile Picture Community Member Microsoft Employee

One way to lock down a form is through JavaScript.

Let’s go through how to do this by looking at the code.

var formCustomizations = {
    disableForm: function (executionContext) {
        let formContext = executionContext.getFormContext();

let formControls = formContext.ui.controls;

formControls.forEach(element => {
            if (element.getName() != "" && element.getName() != null) {
                element.setDisabled(true);
            }
        });
}
}

Here when the JavaScript Function Is called and the execution parameter is passed, the user can see the desired output.

formContext.ui.controls;

Provides the properties and methods to retrieve information about the user interface (UI) controls for several sub-components of the form.

formControls.forEach(element => {
if (element.getName() != "" && element.getName() != null) {
element.setDisabled(true);}

Here the forEach loop will traverse and see if there are any fields that are not blank and the field value is not null, then set all that fields to read only on that form.

Hope this helps!

The post Make form read-only using JavaScript  appeared first on .

Comments

*This post is locked for comments