Support

Account

Home Forums Backend Issues (wp-admin) jQuery Select2 Controls Reply To: jQuery Select2 Controls

  • I changed the field type to post_object with multiple values enabled for aesthetic reasons. A lot of trial and error and digging found that this works to dynamically change the selected values…

    var selector = '#acf-field_5f1f49df49567-field_5f33ff4c31a81';	
    $(selector)
    .empty() //empty select
    .append($("<option/>") //add option tag in select
        .val("2514335") //set value for option to post it
        .text("Red")) //set a text for show in select
    .append($("<option/>") //add option tag in select
        .val("2514356") //set value for option to post it
        .text("Blue")) //set a text for show in select
    .val(["2514335","2514356"]) //select option of select2
    .trigger("change"); //apply to select2