Simulate browser behavior for selecting first dropdown element in non-multiselect, if no elements are selected by default. props koopersmith. fixes #16190
git-svn-id: http://svn.automattic.com/wordpress/trunk@17252 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
1e7b49cece
commit
52239c3f13
|
@ -14,15 +14,33 @@ window.listTable = {
|
|||
this.$tbody = $('#the-list, #the-comment-list');
|
||||
},
|
||||
|
||||
/**
|
||||
* Simulates form.reset() for all input, select, and textarea elements
|
||||
* within a provided context.
|
||||
*/
|
||||
reset: function( context ) {
|
||||
context = $( context );
|
||||
context = $(context);
|
||||
|
||||
$('input', context).each( function(){
|
||||
this.value = this.defaultValue;
|
||||
this.checked = this.defaultChecked;
|
||||
});
|
||||
$('option', context).each( function(){
|
||||
this.selected = this.defaultSelected;
|
||||
|
||||
$('select', context).each( function(){
|
||||
var options = $('option', this),
|
||||
anySelected = false;
|
||||
|
||||
options.each( function(){
|
||||
this.selected = this.defaultSelected;
|
||||
anySelected = anySelected || this.defaultSelected;
|
||||
});
|
||||
|
||||
// If no options are selected within a single-select dropdown,
|
||||
// select the first element by default.
|
||||
if ( ! this.multiple && ! anySelected )
|
||||
options[0].selected = true;
|
||||
});
|
||||
|
||||
$('textarea', context).each( function(){
|
||||
this.value = this.defaultValue;
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue