WordPress.org

Make WordPress Core

Changeset 17252


Ignore:
Timestamp:
01/11/2011 07:37:43 PM (10 years ago)
Author:
markjaquith
Message:

Simulate browser behavior for selecting first dropdown element in non-multiselect, if no elements are selected by default. props koopersmith. fixes #16190

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/js/list-table.dev.js

    r17239 r17252  
    1515    },
    1616
     17    /**
     18     * Simulates form.reset() for all input, select, and textarea elements
     19     * within a provided context.
     20     */
    1721    reset: function( context ) {
    18         context = $( context );
     22        context = $(context);
     23
    1924        $('input', context).each( function(){
    2025            this.value = this.defaultValue;
    2126            this.checked = this.defaultChecked;
    2227        });
    23         $('option', context).each( function(){
    24             this.selected = this.defaultSelected;
    25         });
     28
     29        $('select', context).each( function(){
     30            var options = $('option', this),
     31                anySelected = false;
     32           
     33            options.each( function(){
     34                this.selected = this.defaultSelected;
     35                anySelected = anySelected || this.defaultSelected;
     36            });
     37           
     38            // If no options are selected within a single-select dropdown,
     39            // select the first element by default.
     40            if ( ! this.multiple && ! anySelected )
     41                options[0].selected = true;
     42        });
     43
    2644        $('textarea', context).each( function(){
    2745            this.value = this.defaultValue;
Note: See TracChangeset for help on using the changeset viewer.