Selectmenu: Filterable demo now filters/refreshes selectmenu widget #7681
Selectmenu: Filterable demo now filters/refreshes selectmenu widget #7681
Conversation
2e61ffd
to
800081b
Compare
// We only handle the appearance of a dialog generated by a filterable selectmenu | ||
if ( !$( ".filterable-select" ).is( function() { | ||
return ( ( $( this ).attr( "id" ) + "-dialog" ) === id ); | ||
})) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a pretty ugly if why dont we just do $( ".filterable-select" ).attr( "id" ) + "-dialog" !== id
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... because $( ".filterable-select" )
contains multiple elements and we need to check the id of each, not just the first.
Do you think the following alternative is more legible?
var dialogBelongsToSelectmenu = false;
$( ".filterable-select" ).each( function() {
if ( $( this ).attr( "id" ) + "-dialog" === id ) {
dialogBelongsToSelectmenu = true;
return false;
}
});
if ( dialogBelongsToSelectmenu ) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another alternative is to keep the check but improve the comment. Something like
// Check all the select menus to see if the id of the dialog matches the id of one of them, because
// we only handle the appearance of a dialog generated by a filterable selectmenu
0720195
to
8af51cc
Compare
id = page && page.attr( "id" ); | ||
|
||
$( ".filterable-select" ).each( function() { | ||
if ( ( $( this ).attr( "id" ) + "-dialog" ) === id ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove unneeded parens
👍 |
Fixes gh-7677
... and actually fixes a bug in the existing selectmenu-custom-filter demo whereby the filter input does not return to the popup if the menu is ever shown as a dialog.