Wordpress Gravity form doesn't take in account my select2js value

Hi there! I have an issue that a stucking with for 2 days now…
I have a wordpress site with Gravity form Elite plugin. I created a form with some fields and a select field which I tagged with select2js classes.
This select2js field make an ajax request and display the espected result, then when I select a value, I’m able to get the datas link to the object selected and pre-fill some other fields.
However, I move from CF7 to Gravity Form (client request) and my select2js field doesn’t populate his own field anymore… I see the value in the select2js field but when I submit the form the field has the option value and not the selected value.

Well, some screen/code will be better :
my form.js file with select2js setup: https://gist.github.com/Xutyr/479dc10475d25cedafd49617845cbba6

My select2js with expected value:

If I select for instance the first one “Test Oceane” I got “Test” in the select2js field

So the value is well select in the field but if I look to the HTML I have this:

End finally when I submit the form, it’s the option value 1144 which is saved and not my Test. I compared my gravity form html structure with the previous CF7 usage. I have this on the select2js selection:

<span class="select2-selection__rendered" id="select2-nom-container" role="textbox" aria-readonly="true" title="Mme">
  <span class="select2-selection__clear" title="Remove all items" data-select2-id="122">×</span>
  Test
</span>

The “data-select2-id” data field and the remove items span are missing, furthermore on the previous screen the option created in the select field is weird:

<option value="1144" title="Mme" data-select2-id="select2-data-92-jqbu"></option>

I have no idea how to fix it :frowning: I tried so much thing…
If someone could help me, it’s will be great!

Note: If I create a new tags I don’t have any issue because the option value is the tag value.
Edit: I setup the same version of the plugin (v12), I’m getting the same DOM now. But still have the value like 1144 saved instead of Test.

Kind regards
Xutyr

1 Like

Ok I found the issue…

In my ajax request I return data with the bdd id of the element. So this is the value submit to the form and add to the value selected…
So I think the solution is to add an hidden field that get the right value because the user name is not unique?

Otherwise sorry for the inconvenient.

1 Like

It would help me if I could see the format of the data returned from your AJAX endpoint. I think it’s possible the format doesn’t exactly match what Select2 expects. Could you provide an example of the data returned from your AJAX endpoint (/wp-admin/admin-ajax.php)?

@Xutyr I was facing same problem then I think it will help me for understanding this format as well. :slightly_smiling_face: