I’m using BP XProfile Custom Field Types plugin to add a “Tags” field (select2-based multiselect) to the user profiles.
After the edit profile page loads, I’m dynamically adding new options to my field using the first “Barn Owl” example code from the select2 docs here: https://select2.org/programmatic-control/add-select-clear-items
var data = { id: 1, text: 'Barn owl' }; var newOption = new Option(data.text, data.id, false, false); $('#mySelect2').append(newOption).trigger('change');
Everything works perfectly on the frontend. Users are able to see and select my new dynamically-created “Barn Owl” option.
But when user hits SAVE CHANGES, any dynamically-created selected values will not actually save to the database. Only pre-defined or user-typed values actually get saved properly.
Any idea what the problem is or how to resolve? Thanks!
Hi Evan,
I am sorry, I am not sure of the issue.The plugin expects you to send the terms(text string) as array.
We filter onbp_xprofile_set_field_data_pre_validate
to test for the field type and if the field type is tag, we create terms for any of the non existing term.Please take a look at the submitted form and see if the value is sent as array.
Regards
BrajeshThank you for the reply! Eventually I found the problem was related to the id: in the example code above. I was using numbers as shown in the example, thinking it was equivalent to an array key. But it seems it’s more equivalent to a “value”. So changing it to text with this code resolved everything:
var data = { id: 'Barn owl', text: 'Barn owl' };
The topic ‘ [Resolved] BP XProfile Custom Field – Dynamically-created multiselect values won’t save’ is closed to new replies.