Make WordPress Core

Changeset 44680


Ignore:
Timestamp:
01/21/2019 10:09:48 PM (8 years ago)
Author:
pento
Message:

Menus: Remove error styling when the user addresses the error.

An error is triggered if a Menu Name isn't given when the user attempts to create a menu. When they go back and add a name, the error styling can be removed.

Props ashokrd2013, piyush9100, welcher, afercia.
Fixes #42321.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/_enqueues/lib/nav-menu.js

    r44539 r44680  
    836836                                }
    837837                        });
     838
     839                        $( '#menu-name' ).on( 'input', _.debounce( function () {
     840                                var menuName = $( document.getElementById( 'menu-name' ) ),
     841                                        menuNameVal = menuName.val();
     842
     843                                if ( ! menuNameVal || ! menuNameVal.replace( /\s+/, '' ) ) {
     844                                        // Add warning for invalid menu name.
     845                                        menuName.parent().addClass( 'form-invalid' );
     846                                } else {
     847                                        // Remove warning for valid menu name.
     848                                        menuName.parent().removeClass( 'form-invalid' );
     849                                }
     850                        }, 500 ) );
     851
    838852                        $('#add-custom-links input[type="text"]').keypress(function(e){
    839853                                $('#customlinkdiv').removeClass('form-invalid');
     
    11671181                        menuNameVal = menuName.val();
    11681182                        // Cancel and warn if invalid menu name
    1169                         if( !menuNameVal || menuNameVal == menuName.attr('title') || !menuNameVal.replace(/\s+/, '') ) {
    1170                                 menuName.parent().addClass('form-invalid');
     1183                        if ( ! menuNameVal || ! menuNameVal.replace( /\s+/, '' ) ) {
     1184                                menuName.parent().addClass( 'form-invalid' );
    11711185                                return false;
    11721186                        }
  • trunk/src/wp-includes/script-loader.php

    r44651 r44680  
    17801780                );
    17811781
    1782                 // Navigation Menus
    1783                 $scripts->add( 'nav-menu', "/wp-admin/js/nav-menu$suffix.js", array( 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable', 'wp-lists', 'postbox', 'json2' ) );
     1782                /*
     1783                 * Navigation Menus: Adding underscore as a dependency to utilize _.debounce
     1784                 * see https://core.trac.wordpress.org/ticket/42321
     1785                 */
     1786                $scripts->add( 'nav-menu', "/wp-admin/js/nav-menu$suffix.js", array( 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable', 'wp-lists', 'postbox', 'json2', 'underscore' ) );
    17841787                did_action( 'init' ) && $scripts->localize(
    17851788                        'nav-menu',
Note: See TracChangeset for help on using the changeset viewer.