0

I am using a jquery ui to display messages, but it is not opening automatically if message is not empty.

<script>
    $(function() {
        $( "#dialog-message" ).dialog({
            autoOpen: false,
            modal: true,
            buttons: {
                Ok: function() {
                $( this ).dialog( "close" );
                }
            }
     });
</script>

<c:choose>
    <c:when test="${not empty message}">
        <div id="dialog-message" title="Server Message">
            <p>'${message}'</p>
        </div>

        <script>
           $( "#dialog-message" ).dialog( "open" );
        </script>
        </c:when>
        <c:otherwise>
        </c:otherwise>
</c:choose>

Just to test if it is working i tried putting a button to open the modal box manually on click and it is working.

And also it will work if I remove autoOpen: false.

thanks

1 Answer 1

0

You have to set autoOpen to true. Demo :http://jsfiddle.net/GCu2D/82/

$(document).ready(function () {
var dialog = $('selector').dialog({
    autoOpen: true,
    buttons: {
        "Yes": function () {
            alert('you chose yes');
        },
            "No": function () {
            alert('you chose no');
        },
            "Cancel": function () {
            dialog.dialog('close');
        }
    }
});
});
4
  • Your answer is connected to "And also it will work if I remove autoOpen: false.", so I guess I just didn't understand how modal message works. thanks. May 7, 2014 at 6:44
  • Setting autoOpen to true will enable the modal dialog to open automatically. By default, it's false, so whether you remove autOpen or add autoOpen:false, it's same thing. It has nothing to do with the empty message.
    – K K
    May 7, 2014 at 6:46
  • Hi kamlesh, I remove autoopen: false and remove $( "#dialog-message" ).dialog( "open" ); if autoopen is default to false then why it is autoshowing then? May 7, 2014 at 13:46
  • Checked jquery ui api and autopen's default is true May 7, 2014 at 13:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.