Make form read only

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
TWendt
Posts: 109
Joined: Mon Sep 08, 2014

26 Apr 2018

Hello all,

i created an form for a Process Change Request. In the form is an dropdown field for the status. When the status is "Completed", the complete form should be read only. Please help.

Best wishes
Tom

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

26 Apr 2018

Dear Tom,
There are at least two options here:
1) Redirect users to Display Form automatically after Status changes to "Completed". This should be easy to do, but might not be perfect as it would be difficult to change Status back, if it was set to "Completed" by mistake.
2) Second option is to disable all fields if Status changes to "Completed". You can find a similar example in this article - https://spform.com/javascript-framework ... ynamically

Let me know if you need any help or have any questions!
Cheers

TWendt
Posts: 109
Joined: Mon Sep 08, 2014

26 Apr 2018

Hi,

many thanks for your fast answer. Do I have to enter each field individually. Because I have too many fields in my form.

Best wishes
Tom

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

26 Apr 2018

Dear Tom,
Please, try to run the following code to disable all fields:

Code: Select all

var fields = $('.fd_field');
var names = [];
for(var i = 0; i < fields.length; i++){
	console.log($(fields[i]).attr('fd_name'));
	var name = $(fields[i]).attr('fd_name');
	names.push(name);
};

for (var i = 0; i < names.length; i++){
	fd.field(names[i]).readonly(true);  
}
PS. One thing to note, you also need to turn all fields editable again prior to saving a form, otherwise the values would disappear.
So I would use the following code:

Code: Select all

var fields = $('.fd_field');
var names = [];
for(var i = 0; i < fields.length; i++){
	console.log($(fields[i]).attr('fd_name'));
	var name = $(fields[i]).attr('fd_name');
	names.push(name);
};

function disableFieldsIfCompleted() {
  if (fd.field('Status').value() == 'Completed') {
        for (var i = 0; i < names.length; i++){
	    fd.field(names[i]).readonly(true);  
        }
    } else {
        for (var i = 0; i < names.length; i++){
	    fd.field(names[i]).readonly(false);  
        }
  }
}
 
// Calling function when the user changes the status
fd.field('Status').change(disableFieldsIfCompleted);
 
// Calling function on form loading
disableFieldsIfCompleted();
 
// Enabling fields before the submission
fd.onsubmit(function () {
  for (var i = 0; i < names.length; i++){
	    fd.field(names[i]).readonly(false);  
  }
  return true;
});
Cheers

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 5 guests