jQuery UI Dialog - missing close icon

JavascriptJquery UiJquery Ui-DialogImagebutton

Javascript Problem Overview


I'm using a custom jQuery 1.10.3 theme. I downloaded every straight from the theme roller and I have intentionally not changed anything.

I created a dialog box and I get an empty gray square where the close icon should be: Screen shot of missing close icon

I compared the code that is generated on my page:

Title

To the code generated on the Dialog Demo page:

Basic dialog

EDIT

The different parts of the code are generated by jQueryUI, not me so I can't just add the span tags without editing the jqueryui js file which seems like a bad/unnecessary choice to achieve normal functionality.

Here is the JavaScript used that generates that part of the code: this.element.dialog({ appendTo: "#summary_container", title: this.title(), closeText: "Close", width: this.width, position: { my: "center top", at: ("center top+"+(window.innerHeight*.1)), collision: "none" }, modal: false, resizable: false, draggable: false, show: "fold", hide: "fold", close: function(){ if(KOVM.areaSummary.isVisible()){ KOVM.areaSummary.isVisible(false); } } });

I'm at a loss and need help.

Javascript Solutions


Solution 1 - Javascript

I am late to this one by a while, but I'm going to blow your mind, ready?

The reason this is happening, is because you are calling bootstrap in, after you are calling jquery-ui in.

Literally, swap the two so that instead of:

<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script src="js/bootstrap.min.js"></script>

it becomes

<script src="js/bootstrap.min.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>

:)

> Edit - 26/06/2015 - this keeps attracting interest months later so I > thought it was worth an edit. I actually really like the noConflict > solution offered in the comment underneath this answer and clarified > by user Pretty Cool as a separate answer. As some have reported issues > with the bootstrap tooltip when the scripts are swapped. I didn't > experience that issue however because I downloaded jquery UI without > the tooltip as I didn't need it because bootstrap. So this issue never > came up for me. > > Edit - 22/07/2015 - Don't confuse jquery-ui with jquery! While > Bootstrap's JavaScript requires jQuery to be loaded before, it doesn't rely on jQuery-UI. So jquery-ui.js can be loaded after bootstrap.min.js, while jquery.js always needs to be loaded before Bootstrap.

Solution 2 - Javascript

This is a comment on the top answer, but I felt it was worth its own answer because it helped me answer the problem.

If you want to keep Bootstrap declared after JQuery UI (I did because I wanted to use the Bootstrap tooltip), declaring the following (I declared it after $(document).ready) will allow the button to appear again (answer from https://stackoverflow.com/a/23428433/4660870)

var bootstrapButton = $.fn.button.noConflict() // return $.fn.button to previously assigned value
$.fn.bootstrapBtn = bootstrapButton            // give $().bootstrapBtn the Bootstrap functionality

Solution 3 - Javascript

This appears to be a bug in the way jQuery ships. You can fix it manually with some dom manipulation on the Dialog Open event:

$("#selector").dialog({
    open: function() {
        $(this).closest(".ui-dialog")
        .find(".ui-dialog-titlebar-close")
        .removeClass("ui-dialog-titlebar-close")
        .html("<span class='ui-button-icon-primary ui-icon ui-icon-closethick'></span>");
    }
});

Solution 4 - Javascript

I found three fixes:

  1. You can just load bootsrap first. And them load jquery-ui. But it is not good idea. Because you will see errors in console.

  2. This:

     var bootstrapButton = $.fn.button.noConflict();
     $.fn.bootstrapBtn = bootstrapButton;
    

helps. But other buttons look terrible. And now we don't have bootstrap buttons. 3. I just want to use bootsrap styles and also I want to have close button with an icon. I've done following:

How close button looks after fix

<!-- language: lang-css -->

    .ui-dialog-titlebar-close {
        padding:0 !important;
    }

    .ui-dialog-titlebar-close:after {
        content: '';
        width: 20px;
        height: 20px;
        display: inline-block;
        /* Change path to image*/
        background-image: url(themes/base/images/ui-icons_777777_256x240.png);
        background-position: -96px -128px;
        background-repeat: no-repeat;
    }

Solution 5 - Javascript

This is reported as broken in 1.10

http://blog.jqueryui.com/2013/01/jquery-ui-1-10-0/ > > phillip on January 29, 2013 at 7:36 am said: In the CDN versions, the > dialog close button is missing. There’s only the button tag, the span > ui-icon is missong.

I downloaded the previous version and the X for the close button shows back up.

Solution 6 - Javascript

I had the same exact issue, Maybe you already chececked this but got it solved just by placing the "images" folder in the same location as the jquery-ui.css

Solution 7 - Javascript

I got stuck with the same problem and after read and try all the suggestions above I just tried to replace manually this image (which you can find it here) in the CSS after downloaded it and saved in the images folder on my app and voilá, problem solved!

here is the CSS:

.ui-state-default .ui-icon {
        background-image: url("../img/ui-icons_888888_256x240.png");
}

Solution 8 - Javascript

I know this question is old but I just had this issue with jquery-ui v1.12.0.

Short Answer Make sure you have a folder called Images in the same place you have jquery-ui.min.css. The images folder must contains the images found with a fresh download of the jquery-ui

Long answer

My issue is that I am using gulp to merge all of my css files into a single file. When I do that, I am changing the location of the jquery-ui.min.css. The css code for the dialog expects a folder called Images in the same directory and inside this folder it expects default icons. since gulp was not copying the images into the new destination it was not showing the x icon.

Solution 9 - Javascript

I'm using jQuery UI 1.8.17 and I had this same issue, plus I had additional css stylesheets being applied to things on the page, including the titlebar color. So to avoid any other issues, I targeted the exact ui elements using the code below:

$("#mydialog").dialog('widget').find(".ui-dialog-titlebar-close").hide();    
$("#mydialog").dialog('widget').find('.ui-icon ui-icon-closethick').hide();

Then I added a close button in the properties of the dialog itself: ...

modal : true,
title: "My Dialog",
buttons: [{text: "Close", click: function() {$(this).dialog("close")}}],
...
		

For some reason I had to target both items, but it works!

Solution 10 - Javascript

Even loading bootstrap after jquery-ui, I was able to fix using this:

.ui-dialog-titlebar-close:after {
   content: 'X' !important;
   position: absolute;
   top: -2px;
   right: 3px;
}

Solution 11 - Javascript

A wise man once helped me.

In the folder where jquery-ui.css is located, create a folder named "images" and copy the below files into it:

> ui-icons_444444_256x240.png > > ui-icons_555555_256x240.png > > ui-icons_777620_256x240.png > > ui-icons_777777_256x240.png > > ui-icons_cc0000_256x240.png > > ui-icons_ffffff_256x240.png

and the close icon appears.

Solution 12 - Javascript

As a reference, this is how I extended the open method as per @john-macintyre's suggestion:

$.widget( "ui.dialog", $.ui.dialog, {
	open: function() {
		$(this.uiDialogTitlebarClose)
			.html("<span class='ui-button-icon-primary ui-icon ui-icon-closethick'></span><span class='ui-button-text'>close</span>");
		// Invoke the parent widget's open().
		return this._super();
	}
});

Solution 13 - Javascript

  just add in css
 .ui-icon-closethick{
 margin-top: -8px!important;
margin-left: -8px!important;

}

Solution 14 - Javascript

If you are calling the dialog() inside the js function, you can use the below bootstrap button conflict codes

 <div class="row">
   <div class="col-md-12">
       <input type="button" onclick="ShowDialog()"  value="Open Dialog" id="btnDialog"/>
   </div>
</div>

<div style="display:none;" id="divMessage">
    <table class="table table-bordered">
        <tr>
            <th>Firstname</th>
            <th>Lastname</th>
            <th>Age</th>
        </tr>
        <tr>
            <td>Giri</td>
            <td>Prasad</td>
            <td>25</td>
        </tr>
        <tr>
            <td>Bala</td>
            <td>Kumar</td>
            <td>24</td>
        </tr>
    </table> 
</div>



<script type="text/javascript">
    function ShowDialog()
    {
        if (typeof $.fn.bootstrapBtn =='undefined') {
            $.fn.bootstrapBtn = $.fn.button.noConflict();
        }
       
        $('#divMessage').dialog({
            title:'Employee Info',
            modal:true
        });
    }
    </script>

Solution 15 - Javascript

Just add in the missing:

<span class="ui-button-icon-primary ui-icon ui-icon-closethick"></span>
<span class="ui-button-text">close</span>

Solution 16 - Javascript

I am having this issue as well. Here is the code that is getting inserted for the close button:

From Web Developer showing the jquery-created code

When I turn off the style="display:none:" on the button, then the close button appears. So for some reason that display:none; is getting set, and I don't see how to control that. So another way to address this might be to simply override the display:none. Don't see how to do that though.

I note that the answer posted by KyleMit does work, but makes a different looking X button.

I also note that this issue does not affect all dialogs on my pages, but just some of them. Some dialogs work as expected; other have no title (ie, the span containing the title is empty) while the close button is present.

I am thinking something is seriously wrong and it might not the time for 1.10.x.

But after further work, I discovered that in some cases the titles were not getting set properly, and after fixing that, the X close button reappeared as it should be.

I used to set the titles like this:

('#ui-dialog-title-ac-popup').text('Add Admin Comments for #' + $ac_userid);

That id does not exist in my code, but is created apparently by jquery from ac-popup and ui-dialog-title. Kind of a kludge. But as I said that no longer works, and I have to use the following instead:

$('.ui-dialog-title').text('Add Admin Comments for #' + $ac_userid);

After doing that, the missing button issue seems to be better, although I am not sure if they are definitely related.

Solution 17 - Javascript

I was facing same issue , In my case JQuery-ui.js version was 1.10.3, After referring jquery-ui-1.12.1.min.js close button started to visible.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionXion DarkView Question on Stackoverflow
Solution 1 - JavascriptDavid GView Answer on Stackoverflow
Solution 2 - JavascriptPretty CoolView Answer on Stackoverflow
Solution 3 - JavascriptKyleMitView Answer on Stackoverflow
Solution 4 - JavascriptEugene CharniauskiView Answer on Stackoverflow
Solution 5 - JavascriptRobertView Answer on Stackoverflow
Solution 6 - JavascriptJuan HernándezView Answer on Stackoverflow
Solution 7 - JavascriptRaul RiveroView Answer on Stackoverflow
Solution 8 - JavascriptJuniorView Answer on Stackoverflow
Solution 9 - JavascriptJames DrinkardView Answer on Stackoverflow
Solution 10 - JavascriptidigloveView Answer on Stackoverflow
Solution 11 - JavascriptBoris PrashchurovichView Answer on Stackoverflow
Solution 12 - JavascriptdeansimcoxView Answer on Stackoverflow
Solution 13 - JavascriptShashidharView Answer on Stackoverflow
Solution 14 - Javascriptgiri-webdevView Answer on Stackoverflow
Solution 15 - JavascriptPlentiful LeeView Answer on Stackoverflow
Solution 16 - JavascriptJeffrey SimonView Answer on Stackoverflow
Solution 17 - Javascriptuser14238667View Answer on Stackoverflow