BuddyDev

Search

[Resolved] BP XProfile Custom Field – Dynamically-created multiselect values won’t save

  • Participant
    Level: Initiated
    Posts: 1
    Evan on #52855

    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!

  • Keymaster
    (BuddyDev Team)
    Posts: 24512
    Brajesh Singh on #52871

    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 on bp_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
    Brajesh

  • Participant
    Level: Initiated
    Posts: 1
    Evan on #52891

    Thank 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.

This topic is: resolved