1

My form contains 5 drop-down lists. I'm using JQuery Select2 for each drop-down list. When I'm trying to edit it only one drop-down list shows previous set value.

My code:

$('.select2').select2({
  //placeholder: 'Select an option'
});

if (data.candidateId !== '') {
  $("#candidateParentId").select2().select2(data.candidateParentId, data.parent);
  $("#candidateTypeId").select2().select2(data.candidateTypeId, data.candidateType);
}

But this code shows only Candidate Parent Value and not Candidate Type value.

I'm getting both values in console.

I just refer to this: How to set selected value of jquery select2?

Any kind of help is appreciated. Thanks in advance.

Ganesh Aher
  • 1,118
  • 3
  • 21
  • 51
  • Check this link. [link](https://jsfiddle.net/ahmadtarawneah/o0uxjjtq/23/) – Uxmaan Ali Mar 15 '19 at 14:09
  • This link shows only for single drop-down list, need more than one drop-down on the same form. – Ganesh Aher Mar 16 '19 at 04:53
  • $("#candidateParentId").select2().select2('val', data.candidateParentId); $("#candidateTypeId").select2().select2('val',data.candidateTypeId); Here you can try this. data.candidateParentId or data.candidateTypeId values are present in your dropdowns – Uxmaan Ali Mar 16 '19 at 19:33

1 Answers1

0

Try this

$("#candidateParentId").select2("val", data.parent);

$("#candidateTypeId").select2("val", data.candidateType);
Anas Abu Farraj
  • 1,540
  • 4
  • 23
  • 31
Annamalai
  • 109
  • 2
  • 12
  • Welcome to Stack Overflow! please format your code and add more details to the answer for other developers to understand what exactly you're trying to explain. – Anas Abu Farraj Mar 15 '19 at 13:56