1
votes

This one is really bugging me. I'm getting an error in my console of Uncaught Error: cannot call methods on dialog prior to initialization; attempted to call method 'close'

$( function() {
    $('#search_all_notes_input').dialog({
        autoOpen: false,
        show: {
            effect: "blind",
            duration: 1000
        },
        hide: {
            effect: "explode",
            duration: 1000
        }
    });

    /* Make the Search div a button and open dialog on click */
    $( "#search_all_button" ).button().click(function() {       
        $( "#search_all_notes_input" ).dialog( "open" );
    });
});

$('#submit_search_all_button').click( function () {
    var searchText = $('#search_all_text').val();       
    var query = location.search.split('=');
    var urlMrn = query[1];
    formData = { mnr: urlMRN, search_text: searchText };
    console.log(formData);
    //$.post('note_search.php', formData, getMatchedNotes(data));
    $(this).dialog('close');
});

Any ideas? I'm using a button element inside my dialog div instead of a custom dialog button. Also, the script is loaded at the very end of my HTML page

1
this inside your click event is referring to the button itself, not the modal/dialog, therefore you cannot call close on it. You'll need to call close on the DOM element you initialized the dialog on. You do it on the open event: $( "#search_all_notes_input" ).dialog( "open" );, target the same element when you wish to close it.Ken

1 Answers

1
votes

The problem is you're calling the dialog('close') on the #submit_search_all_button button, not the #search_all_notes_input element that you originally created a dialog on.

Instead of $(this).dialog('close');, use this:

$('#search_all_notes_input').dialog('close');