cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Filtering Dropdown using JQuery

Hi,

I recently ran into an interesting issue. I am populating Nintex multichoice drop downs using Jquery. My form loads find and the drop down controls populate and cascade properly but when submitting the document I get the below error:

Nintex.Workflow.NWException: Error getting context data for 'ContextItemUrl'. ---> System.Exception: Cannot find item with id 0 in list 'listname' . Check the user has at least read permissions. Current user: useraccount. ---> System.ArgumentException: Item does not exist. It may have been deleted by another user.

 

I believe this may be related to postback and viewstate as mentioned here: https://community.nintex.com/thread/2395

However, I'm not able to figure out how to properly filter the dropdowns once i have the data loaded.

 

I'm attaching the code I used to populate my dropdowns. Any help on how to get around this would be much appreciated.

 

Note, the code works great with ListLookup controls but I have 2 lists that go way over the threshold so I can't utilize these and need to use a standard dropdown control to overcome that issue.

 

Thanks!

Labels: (2)
Reply
12 Replies
Not applicable

Re: Filtering Dropdown using JQuery

Addtionally:

I'm noticing something happening:

1. The choice control loads properly in the view but does not load in the source code while list lookup controls load correctly.

This leads me to believe that the javascript isn't populating the initial dropdown value properly.

Here is how I set the value in the dropdown choice control initially:

NWF$(document).ready(function(){

setDropDown();

});

function setDropDown(){

var restQuery = "http://site.com/_vti_bin/ListData.svc/SourceList?$expand=ColumnName"

NWF$.getJSON(restQuery, function (data){

var options = "<option value='0'>(None)</option>";

NWF$(data.d.results).each(function () {

options += "<option value=" +this.Id + ">" +this.ColumnName + "</option>";

});

NWF$("#" + JAVAvariable).html(options);

});

}

So in summation I believe my issue is twofold 1. I need to set the dropdown values initially somehow so the viewstate knows they are there and 2. I need to be able to cascade those options somehow without breaking the viewstate.

0 Kudos
Accept as Solution Reply
Not applicable

Re: Filtering Dropdown using JQuery

Is there any way to utilize Page_Prerender or equivalent in Nintex Forms? I believe the issue is being able to populate the control before the viewstate is fully loaded?

0 Kudos
Accept as Solution Reply
Not applicable

Re: Filtering Dropdown using JQuery

Ok people,

I have a workaround for this issue but it is just that, a workaround.

 

Since the viewstate can't be updated directly from javascript and there's no way to do it with nintex (from what I can tell) I had to implement the below:

 

1. Ensure you have some type of default value for your dropdown, can be anything.

2. Create a textbox control for each of your troubled dropdowns (the one's you're loading values for dynamically)

3. Use the below jquery to transfer the users selected option from the dropdown into the said textbox to save back to the list, then reset the dropdown after selection back to 'nothing' so that the form validation won't see any issues.

 

function setTextBoxFromDropDown(){

    var selection =NWF$("#" + dropDownID + ' option:selected');

    var selectionText = selection.text();

    NWF$("#" + textBoxID).val(selectionText);

    NWF$("#" + dropDownID).prop('selectedIndex', 0);

}

 

this will allow your form to save back properly while maintaining some semblance of what the user selects.

 

Full code (for cascading values from dropDownID1 to dropDownID2):

 

NWF$(document).ready(function (){

var dropdown;

dropdown = NWF$("#" + dropDownID1);

 

dropdown.change(refreshDropdown);

dropdown.change(setTextBoxFromDropDown);

 

}

function refreshDropdown(){

var selectedItem ="";

selectedItem = NWF$("#" + dropDownID1 + ' option:selected').text();

 

var convertedText = encodeURIComponent(selectedItem);

if (convertedItem.indexOf("'") >= 0)

{

convertedItem = convertedItem.replace("'", "''");

 

var restQuery = "http://yoursite.com/_vti_bin/ListData.svc/List?$expand=column&$filter=column eq '" convertedItem + "'"

 

NWF$.getJSON(restQuery, function (data) {

 

var options = "<option value='0'>(None)</option>';

 

NWF$(data.d.results).each(function(){

options += "<option value='" + this.Id + "'>" this.column + "</option>";

});

NWF$("#" + dropDownID2).append(options);

});

}

 

function setTextBoxFromDropDown){

var selection =NWF$("#" + dropDownID2 + ' option:selected');

    var selectionText = selection.text();

    NWF$("#" + textBoxID).val(selectionText);

    NWF$("#" + dropDownID2).prop('selectedIndex', 0);

}

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: Filtering Dropdown using JQuery

Thanks for sharing your workaround charvey! Did you have any luck on a solution that doesn't involve an additional text control?

I'm seeing a similar issue with cascading drop-downs and am trying to avoid that kind of additional overhead on an already custom solution.

0 Kudos
Accept as Solution Reply
Not applicable

Re: Filtering Dropdown using JQuery

I have tried this code but no luck.

Case 1 : We have implemented Core  J-query code .aspx format from and its working fine.

Case: 2 : while we Converted ASPX from into Nintex form and tried to use above code its done't work, Please suggest    

0 Kudos
Accept as Solution Reply
Not applicable

Re: Filtering Dropdown using JQuery

Dear All

I have tried this code but no luck.

Case 1 : We have implemented Core  J-query code .aspx format from and its working fine.

Case: 2 : while we Converted ASPX from into Nintex form and tried to use above code its done't work, Please suggest

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: Filtering Dropdown using JQuery

Yikes!!!! This workaround works but it is not what I'd expect from Nintex.  I sure hope someone is looking at this and considering coming up with a better answer.  Also, the referenced link in the answer appears to be broken.

Regards,

Eric

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: Filtering Dropdown using JQuery

We have a dynamic cascaded dropdown control based on values lookup columns using REST, same interim textbox work around populates the dropdown controls fine and filters correctly as well.

But validation of the controls in Nintex form with isNullOrEmpty (of the textbox values and its set on the dropdown controls) disables the dynamic dropdowns once save/submit is clicked on the form.

Any of you face the same issue? Or have a workaround for the same?

Thanks!

Swetha Sankaran

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: Filtering Dropdown using JQuery

Hi ,

I don't recall any controls being disabled.  Can you share your code? 

0 Kudos
Accept as Solution Reply