WordPress.org

Make WordPress Core

Changeset 49717


Ignore:
Timestamp:
12/01/2020 07:30:16 AM (4 months ago)
Author:
azaozz
Message:

Quick/Bulk Edit: Fix undefined error when initializing UI Autocomplete 1.12.1 on non-existing element and then attempting to use the autocomplete instance.

Example: jQuery( '#nonexisting' ).autocomplete().autocomplete( 'instance' ).something.

Props _luigi, sabernhardt, donmhico, azaozz.
Reviewed by SergeyBiryukov, azaozz.
Merges [49703] and [49710] to the 5.6 branch.
Fixes #51872.

Location:
branches/5.6
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/5.6

  • branches/5.6/src/js/_enqueues/admin/inline-edit-post.js

    r49213 r49717  
    329329                textarea = $('textarea.tax_input_' + taxname, editRow),
    330330                comma = wp.i18n._x( ',', 'tag delimiter' ).trim();
     331
     332            // Ensure the textarea exists.
     333            if ( ! textarea.length ) {
     334                return;
     335            }
    331336
    332337            terms.find( 'img' ).replaceWith( function() { return this.alt; } );
  • branches/5.6/src/js/_enqueues/admin/tags-suggest.js

    r48650 r49717  
    3838        var last;
    3939        var $element = $( this );
     40
     41        // Do not initialize if the element doesn't exist.
     42        if ( ! $element.length ) {
     43            return this;
     44        }
    4045
    4146        options = options || {};
     
    147152        $element.on( 'keydown', function() {
    148153            $element.removeAttr( 'aria-activedescendant' );
    149         } )
    150         .autocomplete( options )
    151         .autocomplete( 'instance' )._renderItem = function( ul, item ) {
     154        } );
     155
     156        $element.autocomplete( options );
     157
     158        // Ensure the autocomplete instance exists.
     159        if ( ! $element.autocomplete( 'instance' ) ) {
     160            return this;
     161        }
     162
     163        $element.autocomplete( 'instance' )._renderItem = function( ul, item ) {
    152164            return $( '<li role="option" id="wp-tags-autocomplete-' + item.id + '">' )
    153165                .text( item.name )
     
    169181                $element.autocomplete( 'search' );
    170182            }
    171         } )
     183        } );
     184
    172185        // Returns a jQuery object containing the menu element.
    173         .autocomplete( 'widget' )
     186        $element.autocomplete( 'widget' )
    174187            .addClass( 'wp-tags-autocomplete' )
    175188            .attr( 'role', 'listbox' )
Note: See TracChangeset for help on using the changeset viewer.