cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Nintex Newbie

Re: Filtering Dropdown using JQuery

Thanks Eric,

Here is the code and sorry about the length. Once I hit submit, the dropdown list becomes non-editable. I'm using SPServices to get current user and group membership information. Cascaded dropdown populates as expected, validation on the form on submit works as expected, but once the first validation is done, the dropdowns get grayed out dont' work or save values.

The dropdowns are simple choice controls on the form. Jeremy Jaya Raj‌ any help is appreciated.

F12 - debugger console doesn't show any error.

var isUserInEUCPO;
var currentUser;

NWF$(document).ready(
  function() {
    NWF.FormFiller.Events.RegisterAfterReady(function() {
      currentUser=$().SPServices.SPGetCurrentUser({
      fieldName:"Title",
      debug:false
      });
      var ddlDivision = NWF$("#" + ddlDivisionID);
      var ddlDepartment = NWF$("#" + ddlDepartmentID);
      var txtPrimaryArchitects = NWF$("#" + txtPrimaryArchitectsID);
      var divisionval = "";
      if (ddlDivision != null) {
        NWF$("#" + ddlDivisionID).change(function() {
          divisionval = this.value;
          if (divisionval == "**SelectValue**")
            divisionval = "";
          //Clear filtered department on division change
          $('option', ddlDepartment).not(':eq(0)').remove();
          Populate_Departments(divisionval);
          var decodedDivision = decodeURIComponent(divisionval);
          NWF$("#" + txtSelectedDivisionID).val(decodedDivision);
          NWF$("#" + txtSelectedDivisionID).blur();
        });
   
        isUserInEUCPO = IsUserInEUCPO();

        //Remove dummy entry from the dropdown
        ddlDivision.find("option[value='None']").remove();

        Populate_Divisions();

        //Load
        NWF$("#" + txtSelectedDivisionID).val(NWF$("#" + ddlDivisionID).val());

      }
      if (ddlDepartment != null) {
        NWF$("#" + ddlDepartmentID).change(function() {
          var departmentval = this.value;
          if (departmentval == "**SelectValue**")
            departmentval = "";

          var decodedDept = decodeURIComponent(departmentval);

          NWF$("#" + txtSelectedDepartmentID).val(decodedDept);
          NWF$("#" + txtSelectedDepartmentID).blur();
          Populate_Architects(departmentval, txtPrimaryArchitects);
        });

        ddlDepartment.find("option[value='None']").remove();
        Populate_Departments();
      }
    });
  }
);

function Populate_Divisions() {
  var siteURL = $().SPServices.SPGetCurrentSite();
  var requestURL;
  if (isUserInEUCPO == true) {
    requestURL = siteURL + "/_api/web/Lists/getbytitle('Division Architect')/Items?$select=Division,Department&$order=Division";
  }
  else {
      requestURL = siteURL + "/_api/web/Lists/GetByTitle('Division Architect')/Items?$select=Division,Architect/Title&$expand=Architect&$filter=Architect/Title eq '"+currentUser+"'"
  }
  var results;
  var ddlDivision = NWF$("#" + ddlDivisionID);
  $.ajax({
    url: requestURL,
    method: "GET",
    async: false,
    headers: {
      "Accept": "application/json; odata=verbose"
    },
    success: function(data) {
      results = data.d.results;
      if (results.length > 0) {
        for (ctr = 0; ctr < results.length; ctr++) {
          division = results[ctr].Division;
          var encodedDivision = encodeURIComponent(division);
          if (ddlDivision.find("option[value='" + encodedDivision + "']") == null || ddlDivision.find("option[value='" + encodedDivision + "']").length == 0) {
            ddlDivision.append($('<option></option>').val(encodedDivision).html(division));
          }
        }
      }
    },
    error: function(data) {
      alert(data.status + ' ' + data.statusText);
    }
  });

}

function Populate_Departments(divisionval) {
  var siteURL = $().SPServices.SPGetCurrentSite();
  var requestURL;
  if (isUserInEUCPO == true) {
    requestURL = siteURL + "/_api/web/Lists/getbytitle('Division Architect')/Items?$select=Division,Department&$filter=Division eq '"+divisionval+"'&$order=Department";
  }
  else {
      requestURL = siteURL + "/_api/web/Lists/GetByTitle('Division Architect')/Items?$select=Division,Department,Architect/Title&$expand=Architect&$filter=((Architect/Title eq '"+currentUser+"') and (Division eq '" + divisionval + "'))&$order=Department";
  }
  var results;
  var ddlDepartment = NWF$("#" + ddlDepartmentID);
  $.ajax({
    url: requestURL,
    method: "GET",
    async: false,
    headers: {
      "Accept": "application/json; odata=verbose"
    },
    success: function(data) {
      results = data.d.results;
      if (results.length > 0) {
        for (ctr = 0; ctr < results.length; ctr++) {
          department = results[ctr].Department;
          var encodedDepartment = encodeURIComponent(department);
          if (ddlDepartment.find("option[value='" + encodedDepartment + "']") == null || ddlDepartment.find("option[value='" + encodedDepartment + "']").length == 0) {
            ddlDepartment.append($('<option></option>').val(encodedDepartment).html(department));
          }
        }
        //ddlDepartment.append($("<option selected='selected'></option>").val('Please select a value...').html('Please select a value...'));
      }
    },
    error: function(data) {
      alert(data.status + ' ' + data.statusText);
    }
  });

}

function Populate_Architects(departmentval, txtPrimaryArchitects) {
  var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/Lists/GetByTitle('Division Architect')/Items?$select=Department,Architect/Title&$expand=Architect&$filter=Department eq '" + departmentval + "'";
  var requestHeaders = {
    "accept": "application/json;odata=verbose"
  };
  $.ajax({
    url: requestUri,
    contentType: "application/json;odata=verbose",
    headers: requestHeaders,
    success: function(data) {
      var items = data.d.results;
      var users = "";
      for (var i = 0; i < items.length; i++) {
        users += items[i].Architect.Title + "\n";
      }
      txtPrimaryArchitects.val(users);
    },
    error: function(data) {
      alert(data.status + ' ' + data.statusText);
    }
  });

}

function IsUserInEUCPO() {
  var userInEUCPO = false;

  $().SPServices({
    operation: "GetGroupCollectionFromUser",
    userLoginName: $().SPServices.SPGetCurrentUser(),
    async: false,
    completefunc: function(xData, Status) {
      if ($(xData.responseXML).find("Group[Name='EUC Program Office']").length == 1) {
        userInEUCPO = true;
      }
    }
  });
  return userInEUCPO;
}
//Workaround for .net control save issue
function onSave() {
  NWF$('.customDropDown').prop('disabled', true);
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
Reply
Highlighted
Nintex Newbie

Re: Filtering Dropdown using JQuery

I'm not 100% sure but the following code looks like it might be disabling the controls

function onSave() {
  NWF$('.customDropDown').prop('disabled', true);
}
Reply
Highlighted
Nintex Newbie

Re: Filtering Dropdown using JQuery

Yep! That was indeed the culprit. I solved it by adding conditional check for the textboxes value. This way we got to keep our workaround for viewstate and include the validation rule on form dropdowns as well.

Thanks so much Eric.

function onSave() {
 if(decodedDivision != null && decodedDept != null)
      NWF$('.customDropDown').prop('disabled', true);
}

Reply