Make WordPress Core

Changeset 49703


Ignore:
Timestamp:
11/28/2020 12:44:44 PM (6 years 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.
Fixes #51872.

Location:
trunk/src/js/_enqueues/admin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/_enqueues/admin/inline-edit-post.js

    r49213 r49703  
    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; } );
  • trunk/src/js/_enqueues/admin/tags-suggest.js

    r48650 r49703  
    3838                var last;
    3939                var $element = $( this );
     40
     41                // Do not initialize if the element doesn't exist.
     42                if ( ! $element.length ) {
     43                        return;
     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 ) {
    152                         return $( '<li role="option" id="wp-tags-autocomplete-' + item.id + '">' )
    153                                 .text( item.name )
    154                                 .appendTo( ul );
    155                 };
     154                } );
     155
     156                $element.autocomplete( options );
     157
     158                // Ensure the autocomplete instance exists.
     159                if ( $element.autocomplete( 'instance' ) ) {
     160                        $element.autocomplete( 'instance' )._renderItem = function( ul, item ) {
     161                                return $( '<li role="option" id="wp-tags-autocomplete-' + item.id + '">' )
     162                                        .text( item.name )
     163                                        .appendTo( ul );
     164                        };
     165                }
    156166
    157167                $element.attr( {
Note: See TracChangeset for help on using the changeset viewer.