Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a test case for which this ternary operation evaluates to false?

Tags:

jquery

I need help understanding the jquery ui autocomplete example found here: http://jqueryui.com/demos/autocomplete/#remote

If you click on the source

$(function() {
    function log( message ) {
        $( "</div>" ).text( message ).prependTo( "#log" );
        $( "#log" ).scrollTop( 0 );
    }

    $( "#birds" ).autocomplete({
        source: "search.php",
        minLength: 2,
        select: function( event, ui ) {
            log( ui.item ?
                "Selected: " + ui.item.value + " aka " + ui.item.id :
                "Nothing selected, input was " + this.value );
        }
    });
});

You'll see that when you select a suggested entry, that entry's information will be parsed into the log. However, is there an actual use case where ui.item evaluates to false and the 2nd statement executes and gets stored in the log?

like image 581
user784637 Avatar asked Feb 01 '26 06:02

user784637


1 Answers

Autocomplete select event: "Triggered when an item is selected from the menu; ui.item refers to the selected item".

If ui.item is false no item was selected, but then the autocomplete select event would't have fired.

like image 160
ori Avatar answered Feb 04 '26 01:02

ori



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!