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

jquery code to remove / add options to dropdownlist (choice field)

Jump to solution

Hi Team,

I have been implemented the code to remove Options from dropdownlist using the following code.

foo = "0 - Not applicable";
NWF$("#" + LossStatus + " option:contains(" + foo +")").remove();
foo = "1 - Loss not yet closed";
NWF$("#" + LossStatus + " option:contains(" + foo +")").remove();
foo = "2 - Loss closed";
NWF$("#" + LossStatus + " option:contains(" + foo +")").remove();

after that base on my condition i would like to add options to my dropdownlist with the following code.

NWF$('#' +LossStatus).append($('<option>', {value: 1,text: '1 - Loss not yet closed'}));

How ever its showing in dropdown. but could not able to save the form.

Showing error as "Some thing went wrong" and some correlation id.

Please help us to the correct way to add options to dropdown,

Regards,

Dhayanand

Labels: (2)
Tags (1)
0 Kudos
Reply
3 Replies
Automation Master
Automation Master

Re: jquery code to remove / add options to dropdownlist (choice field)

Jump to solution

Hi there - 

So from looking at what you have here, I would say that you'd want a list with your dropdown items - and then a column with something that will allow you to filter on it to hide / show things as required.

For example - the column could be "manager" with "yes" and "no" for each item - as in, can a manager view this? Then, you could use a ListLookup and filter on the field "Manager" - controlled by a single line of text in your form (that you'll hide) and update based on whatever you need to filter with. Like, "if the current user is a manager, then this will be YES... if not, then NO." That kind of thing.

So in your case ... if control is equal to 0 not applicable, then filter using "not applicable", otherwise, use "applicable."

0 Kudos
Reply
dhayanandkalimi
Nintex Newbie

Re: jquery code to remove / add options to dropdownlist (choice field)

Jump to solution

removing option from dropdown list

foo = "0 - Not applicable";
NWF$("#" + LossStatus + " option:contains(" + foo +")").remove();

adding option to dropdown list

NWF$('#' +LossStatus).append($('<option>', {
value: '1 - Loss not yet closed',
text: '1 - Loss not yet closed'
}));

Removing duplicate option values in dropdown

var usednames={};
$("select[id="+LossStatus+"]>option").each(function(){
if(usednames[this.text]){
$(this).remove();
}
else{
usednames[this.text]=this.value;
}
});

View solution in original post

Reply
dhayanandkalimi
Nintex Newbie

Re: jquery code to remove / add options to dropdownlist (choice field)

Jump to solution

removing option from dropdown list

foo = "0 - Not applicable";
NWF$("#" + LossStatus + " option:contains(" + foo +")").remove();

 

adding option to dropdown list

NWF$('#' +LossStatus).append($('<option>', {
value: '1 - Loss not yet closed',
text: '1 - Loss not yet closed'
}));

 

Removing duplicate option values in dropdown

var usednames={};
$("select[id="+LossStatus+"]>option").each(function(){
if(usednames[this.text]){
$(this).remove();
}
else{
usednames[this.text]=this.value;
}
});

0 Kudos
Reply