Home Forums General Issues How to set null on select2 data & select2 value?


How to set null on select2 data & select2 value?

  • I am using 2 taxonomy dropdown. on 1st dropdown, I want only parent terms on second, I want only child terms from parent term using 1st dropdown. I am able to fetch the child and parent term using “select2_ajax_data” filter but I am not able to set null on 2nd dropdown.

    acf.add_filter( "select2_ajax_data", function( data, args, $input, field, instance ) {
      if ( data.field_key === "field_5e6e4d63c51b1" ) {
        var field = acf.getField( "field_5d63457a6c2d8" );
        data.parent = field.val();
      return data;
    } );

    I am using this code for on change event

    var instance = new acf.Model( {
      events: {
        'change select#acf-field_5d63457a6c2d8': 'onChange'
      onChange: function( e, $el ) {
        // do something
        var field = acf.getField( "field_5e6e4d63c51b1" );
        // I want to set value to null
        // Also i want to clear old options that was fetched in last ajaxcall
    } );
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.