Make WordPress Core

Ticket #42373: 42373.4.diff

File 42373.4.diff, 7.8 KB (added by westonruter, 8 years ago)
  • src/wp-admin/js/customize-controls.js

    diff --git src/wp-admin/js/customize-controls.js src/wp-admin/js/customize-controls.js
    index 0504891969..6e1f513ef5 100644
     
    55525552                                var input = $( this ), component, element;
    55535553                                component = input.data( 'component' );
    55545554                                element = new api.Element( input );
    5555                                 if ( 'meridian' === component ) {
    5556                                         element.validate = function( value ) {
    5557                                                 if ( 'am' !== value && 'pm' !== value ) {
    5558                                                         return null;
    5559                                                 }
    5560                                                 return value;
    5561                                         };
    5562                                 } else {
    5563                                         element.validate = function( value ) {
    5564                                                 var val = parseInt( value, 10 );
    5565                                                 if ( isNaN( val ) ) {
    5566                                                         return null;
    5567                                                 }
    5568                                                 return val;
    5569                                         };
    5570                                 }
    5571                                 element.bind( control.populateSetting );
    55725555                                control.inputElements[ component ] = element;
    55735556                                control.elements.push( element );
     5557
     5558                                // Add invalid date error once user changes (and has blured
     5559                                input.on( 'change', function() {
     5560                                        if ( control.invalidDate ) {
     5561                                                control.notifications.add( new api.Notification( 'invalid_date', {
     5562                                                        message: api.l10n.invalidDate
     5563                                                } ) );
     5564                                        }
     5565                                } );
     5566                                input.on( 'input', _.debounce( function() {
     5567                                        if ( ! control.invalidDate ) {
     5568                                                control.notifications.remove( 'invalid_date' );
     5569                                        }
     5570                                } ) );
    55745571                        } );
    55755572
    55765573                        control.inputElements.month.bind( control.updateDaysForMonth );
     
    55805577                        }
    55815578                        control.populateDateInputs();
    55825579                        control.setting.bind( control.populateDateInputs );
     5580
     5581                        // Start populating setting after it has been populated.
     5582                        _.each( control.inputElements, function( element ) {
     5583                                element.bind( control.populateSetting );
     5584                        } );
    55835585                },
    55845586
    55855587                /**
     
    56295631                 * @return {boolean} If date input fields has error.
    56305632                 */
    56315633                validateInputs: function validateInputs() {
    5632                         var control = this, errorMessage, components;
     5634                        var control = this, components, validityInput;
    56335635
    56345636                        control.invalidDate = false;
    56355637
     
    56385640                                components.push( 'hour', 'minute' );
    56395641                        }
    56405642
    5641                         _.each( components, function( component ) {
    5642                                 var element, el, max, min, value;
     5643                        _.find( components, function( component ) {
     5644                                var element, max, min, value;
     5645
     5646                                element = control.inputElements[ component ];
     5647                                validityInput = element.element.get( 0 );
     5648                                max = parseInt( element.element.attr( 'max' ), 10 );
     5649                                min = parseInt( element.element.attr( 'min' ), 10 );
     5650                                value = parseInt( element(), 10 );
     5651                                control.invalidDate = isNaN( value ) || value > max || value < min;
    56435652
    56445653                                if ( ! control.invalidDate ) {
    5645                                         element = control.inputElements[ component ];
    5646                                         el = element.element.get( 0 );
    5647                                         max = parseInt( element.element.attr( 'max' ), 10 );
    5648                                         min = parseInt( element.element.attr( 'min' ), 10 );
    5649                                         value = element();
    5650                                         control.invalidDate = value > max || value < min;
    5651                                         errorMessage = control.invalidDate ? api.l10n.invalid + ' ' + component : '';
    5652 
    5653                                         el.setCustomValidity( errorMessage );
    5654                                         if ( ! control.section() || api.section.has( control.section() ) && api.section( control.section() ).expanded() ) {
    5655                                                 _.result( el, 'reportValidity' );
    5656                                         }
     5654                                        validityInput.setCustomValidity( '' );
    56575655                                }
     5656
     5657                                return control.invalidDate;
    56585658                        } );
    56595659
     5660                        if ( control.inputElements.meridian && ! control.invalidDate ) {
     5661                                validityInput = control.inputElements.meridian.element.get( 0 );
     5662                                if ( 'am' !== control.inputElements.meridian.get() && 'pm' !== control.inputElements.meridian.get() ) {
     5663                                        control.invalidDate = true;
     5664                                } else {
     5665                                        validityInput.setCustomValidity( '' );
     5666                                }
     5667                        }
     5668
     5669                        if ( control.invalidDate ) {
     5670                                validityInput.setCustomValidity( api.l10n.invalidValue );
     5671                        } else {
     5672                                validityInput.setCustomValidity( '' );
     5673                        }
     5674                        if ( ! control.section() || api.section.has( control.section() ) && api.section( control.section() ).expanded() ) {
     5675                                _.result( validityInput, 'reportValidity' );
     5676                        }
     5677
    56605678                        return control.invalidDate;
    56615679                },
    56625680
     
    56695687                updateDaysForMonth: function updateDaysForMonth() {
    56705688                        var control = this, daysInMonth, year, month, day;
    56715689
    5672                         month = control.inputElements.month();
    5673                         year = control.inputElements.year();
    5674                         day = control.inputElements.day();
     5690                        month = parseInt( control.inputElements.month(), 10 );
     5691                        year = parseInt( control.inputElements.year(), 10 );
     5692                        day = parseInt( control.inputElements.day(), 10 );
    56755693
    56765694                        if ( month && year ) {
    56775695                                daysInMonth = new Date( year, month, 0 ).getDate();
    56785696                                control.inputElements.day.element.attr( 'max', daysInMonth );
    56795697
    56805698                                if ( day > daysInMonth ) {
    5681                                         control.inputElements.day( daysInMonth );
     5699                                        control.inputElements.day( String( daysInMonth ) );
    56825700                                }
    56835701                        }
    56845702                },
     
    56985716
    56995717                        minuteEl = control.inputElements.minute.element;
    57005718
    5701                         if ( maxHours === control.inputElements.hour() ) {
    5702                                 control.inputElements.minute( 0 );
     5719                        if ( String( maxHours ) === String( control.inputElements.hour() ) ) {
     5720                                control.inputElements.minute( '0' );
    57035721                                minuteEl.data( 'default-max', minuteEl.attr( 'max' ) );
    57045722                                minuteEl.attr( 'max', '0' );
    57055723                        } else if ( minuteEl.data( 'default-max' ) ) {
     
    57455763                        };
    57465764
    57475765                        getElementValue = function( component ) {
    5748                                 var value = control.inputElements[ component ].get();
     5766                                var value = parseInt( control.inputElements[ component ].get(), 10 );
    57495767
    57505768                                if ( _.contains( [ 'month', 'day', 'hour', 'minute' ], component ) ) {
    57515769                                        value = pad( value, 2 );
     
    58225840                        }
    58235841
    58245842                        _.each( control.inputElements, function( element, component ) {
    5825                                 element.set( parsed[ component ] );
     5843                                if ( 'meridian' === component || parseInt( parsed[ component ], 10 ) !== parseInt( element() ) ) {
     5844                                        element.set( parsed[ component ] );
     5845                                }
    58265846                        } );
    58275847
    58285848                        return true;
  • src/wp-includes/customize/class-wp-customize-date-time-control.php

    diff --git src/wp-includes/customize/class-wp-customize-date-time-control.php src/wp-includes/customize/class-wp-customize-date-time-control.php
    index 0506910b61..d1e8d12500 100644
    class WP_Customize_Date_Time_Control extends WP_Customize_Control { 
    141141                                        <legend class="title-time"><?php esc_html_e( 'Time' ); ?></legend>
    142142                                        <div class="time-fields clear">
    143143                                                <label for="{{ idPrefix }}date-time-hour" class="screen-reader-text"><?php esc_html_e( 'Hour' ); ?></label>
    144                                                 <# var maxHour = data.twelveHourFormat ? 12 : 24; #>
    145                                                 <input id="{{ idPrefix }}date-time-hour" type="number" size="2" autocomplete="off" class="date-input hour" data-component="hour" min="1" max="{{ maxHour }}">
     144                                                <# var maxHour = data.twelveHourFormat ? 12 : 23; #>
     145                                                <# var minHour = data.twelveHourFormat ? 1 : 0; #>
     146                                                <input id="{{ idPrefix }}date-time-hour" type="number" size="2" autocomplete="off" class="date-input hour" data-component="hour" min="{{ minHour }}" max="{{ maxHour }}">
    146147                                                <span class="time-special-char date-time-separator">:</span>
    147148                                                <label for="{{ idPrefix }}date-time-minute" class="screen-reader-text"><?php esc_html_e( 'Minute' ); ?></label>
    148149                                                <input id="{{ idPrefix }}date-time-minute" type="number" size="2" autocomplete="off" class="date-input minute" data-component="minute" min="0" max="59">
  • src/wp-includes/script-loader.php

    diff --git src/wp-includes/script-loader.php src/wp-includes/script-loader.php
    index c43659379d..e5204a7aa0 100644
    function wp_default_scripts( &$scripts ) { 
    599599                        esc_url( admin_url( 'theme-install.php' ) )
    600600                ),
    601601                'publishSettings' => __( 'Publish Settings' ),
     602                'invalidDate'     => __( 'Invalid date.' ),
     603                'invalidValue'    => __( 'Invalid value.' ),
    602604        ) );
    603605        $scripts->add( 'customize-selective-refresh', "/wp-includes/js/customize-selective-refresh$suffix.js", array( 'jquery', 'wp-util', 'customize-preview' ), false, 1 );
    604606