开发者

jQueryUI .button() remains pressed after opening ui dialog with it in firefox

link for jsfiddle: http://jsfiddle.net/6UWZQ/1

look on this live link, if you click on any row on delete or edit and after click cancel, the button will remain highlighted (only in Firefox)

I make the buttons like this:

$("input[type=submit]").addClass("abtn"); 
$("tbody a").addClass("abtn");
$(".abtn").button();

and I add a confirm dialog for each form by using a css class on the submit button like this:

<script type="text/javascript">
        var currentFormconfirm;
        $(function () {
            $("#dialog-confirm-confirm").dialog({
            show: "drop",
            hide: "fade",
                resizable: false,
                height: 220,
                width: 400,
                modal: true,
                autoOpen: false,
                buttons: {
                    'Yes': function () {
                        $(this).dialog('close');
                        currentFormconfirm.submit();
                    },
                    'Cancel': function () {
                        $(this).dialog('close');
                    }
                }
            });
            $(".confirm").click(function () {
                currentFormconfirm = $(this).closest('form');
                $("#dialog-confirm-confirm").dialog('open');
                return false;
            });
        });

</script>
<div id="dialog-confirm-confirm" title="Confirm dialog">
    Are you sure you want to delete this foobar ?
</div>

and the form:

&l开发者_如何学JAVAt;form action="/awesome/foobar/Delete/7" method="post" class="fr">
                    <input type="submit" class="confirm abtn ui-button ui-widget ui-state-default ui-corner-all" value="Delete" role="button" aria-disabled="false">
                    </form>


Also a bit late, but...

Combining suggestions above, I was able to fix problem for all buttons on the page by including this in $(document).ready

$("button, input[type='button'], input[type='submit']").button()
    .bind('mouseup', function() {
        $(this).blur();     // prevent jquery ui button from remaining in the active state
});


That seems like a bug in jquery ui 1.8.1. Here's a simplified test case to reproduce the behavior. The problem is that ui-state-focus class is not removed.


Hoang's solution works, but if you don't want to hack the jquery ui source an alternative way is to call removeClass inside your onClick. Example:

button.click(function() {
    button.removeClass("ui-state-focus ui-state-hover");
}

Note, though, that both solutions still have this quirk: if you click and release it will unfocus, but if you switch tabs and come back it'll be focused.


In "jquery-ui-1.8.7.custom.min.js" file, at jQuery UI Button area, change

.bind("mouseup.button",function(){
    if(c.disabled)return false;
    a(this).removeClass("ui-state-active")
})

to

.bind("mouseup.button",function(){
    if(c.disabled)return false;
    a(this).removeClass("ui-state-active ui-state-hover ui-state-focus")
})


I know it's a bit late, but the problem is still existing and I have made an actual simple fix, which is calling the blur function on your button.

$('#myButton').blur();

You call the blur() method right after opening the dialog.

Here is a snippet:

$('#cbDate').button();
if(date == "infinite")
{
    $('#cbDate').checked = true;
    $('label[for=cbDate]').addClass('ui-state-active');
    //This is the interesting part
    $('#cbDate, label[for=cbDate]').blur();
}
else
{
    $('#cbDate, label[for=cbDate]').blur();
}


since it's a jquery bug, my solution is to do this instead of button():

   $(".abtn")
                .hover(function () { $(this).addClass("ui-state-hover"); },
                    function () { $(this).removeClass("ui-state-hover"); })
                .bind({ 'mousedown mouseup': function () { $(this).toggleClass('ui-state-active'); } })
                .addClass("ui-state-default").addClass("ui-corner-all")
                .bind('mouseleave', function() { $(this).removeClass('ui-state-active') });


How about adding to dialog init:

open: function() { $('.ui-button').blur(); }


The following works well in jQuery 1.8.17:

$(document).ready(function() {

    ...

    $(".ui-button").live('click', function() {
        $(this).blur();
        $(this).removeClass("ui-state-focus ui-state-hover");
    });
})
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜