Make form read only
- Nikita Kurguzov
- Posts: 889
- Joined: Mon Jul 03, 2017
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!
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
- Nikita Kurguzov
- Posts: 889
- Joined: Mon Jul 03, 2017
Dear Tom,
Please, try to run the following code to disable all fields:
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:
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);
}
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
-
- Information
-
Who is online
Users browsing this forum: No registered users and 11 guests