Disable multiple dropdown fields

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
enillrae
Posts: 17
Joined: Mon May 29, 2017

02 Jul 2018

Hello,

I would like to make a group of dropdown fields readonly on the Edit form based on a Status field. Please advise.
I've given the fields the css-class name 'form-b4'


Here is a snippet of my code

function setFields() {
if (fd.field('Status').value()=='Pending'){
$('.form-b4').prop('disabled', true);
} else {
$('.form-b4').prop('enabled', true);
}
//status on change
fd.field('Status').control().change(function() {
setFields();
});

//Initialize
setFields();

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

03 Jul 2018

Dear Enillrae,
Try the following code for this:

Code: Select all

//array to store field names:
var fields = [];

//function to get all field names:
function getFields(){
  var dropdowns = $('.form-b4');
  for(var i = 0; i < dropdowns.length; i++){
    var title = $(dropdowns[i]).find('select').attr('title');
    fields.push(title);
  }
}

//get them
getFields();

//function to set all fields to readonly/back
function setFieldsReadonly(bool){
  for(var i = 0; i < fields.length; i++){
    fd.field(fields[i]).readonly(bool);
  }
}

//function to check status and then set fields correctly
function checkStatus(){
  if(fd.field('Title').value() == 'Pending'){
    setFieldsReadonly(true);
  }
  else{
    setFieldsReadonly(false);
  }
}

//run it when form loads
checkStatus();

//run it when Status changes
fd.field('Title').change(function() { checkStatus(); });

//set fields editable again, so they can be saved
fd.onsubmit(function(){
  setFieldsReadonly(false);
  return true;
});
Cheers

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 7 guests