WordPress.org

Make WordPress Core

Opened 4 years ago

Last modified 4 months ago

#16972 reviewing defect (bug)

Input type radio losts its checked focus when metabox is dragged

Reported by: depi Owned by: azaozz
Milestone: Future Release Priority: normal
Severity: normal Version: 3.0
Component: Administration Keywords: has-patch needs-testing
Focuses: javascript Cc:

Description

This happens when I use a radio button in a metabox. Once I try to drag it to different position or just drag and let it go the checked focus is lost. (in code it of course still remain checked, but visually not)

Bug not happens with other fields I tested (checkboxes, inputs, textareas)

Attachments (4)

switch postbox sortable mode.patch (437 bytes) - added by helgatheviking 3 years ago.
delete mode = 'clone' for sortables
16972.2.diff (622 bytes) - added by lessbloat 3 years ago.
16972.3.diff (1.1 KB) - added by lessbloat 3 years ago.
16972.3.refresh.diff (1.1 KB) - added by voldemortensen 8 months ago.

Download all attachments as: .zip

Change History (23)

comment:1 @depi4 years ago

You can check this behavior for example on the Add Link page in WP-Admin where are some radio buttons.

comment:2 @scribu4 years ago

  • Component changed from General to Administration
  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to Future Release
  • Version changed from 3.1 to 3.0

Confirmed. It happens in WP 3.0 too.

comment:3 @ldebrouwer4 years ago

  • Cc info@… added
  • Owner set to ldebrouwer
  • Status changed from new to reviewing

This is a bug/feature in the jQuery UI sortable library ( has been since 1.5.x ). The sortable plugin clones the node being moved which resets the radio buttons.

comment:4 @commentluv4 years ago

I was having this exact issue with meta boxes I am adding to a plugin settings page, everything else is cool but radio buttons lose their happy little dot so saving settings after dragging a metabox to a new position loses that radio buttons setting which messes things up.

after much experimentation and being too bloody minded to remove drag and drop entirely and being too lazy to rejigger the settings to use checkboxes instead and failing to find a way to listen to the metabox drop event, I came up with this which, so far, seems to do the job


// global script for commentluv premium settings pages
// workaround for bug that causes radio inputs to lose settings when meta box is dragged.
// http://core.trac.wordpress.org/ticket/16972
jQuery(document).ready(function(){
    // listen for drag drop of metaboxes , bind mousedown to .hndle so it only fires when starting to drag
    jQuery('.hndle').mousedown(function(){                                                               
        // set live event listener for mouse up on the content .wrap and wait a tick to give the dragged div time to settle before firing the reclick function
        jQuery('.wrap').mouseup(function(){store_radio(); setTimeout('reclick_radio();',50);});
    })
});
/**
* stores object of all radio buttons that are checked for entire form
*/
function store_radio(){
    var radioshack = {};
    jQuery('input[type="radio"]').each(function(){
        if(jQuery(this).is(':checked')){
            radioshack[jQuery(this).attr('name')] = jQuery(this).val();
        }
        jQuery(document).data('radioshack',radioshack);
    });
}
/**
* detect mouseup and restore all radio buttons that were checked
*/
function reclick_radio(){
    // get object of checked radio button names and values
    var radios = jQuery(document).data('radioshack');
    //step thru each object element and trigger a click on it's corresponding radio button
    for(key in radios){
        jQuery('input[name="'+key+'"]').filter('[value="'+radios[key]+'"]').trigger('click');
    }            
    // unbind the event listener on .wrap  (prevents clicks on inputs from triggering function)
    jQuery('.wrap').unbind('mouseup');
}

you just need to change jQuery('.wrap') to whatever container your meta boxes appear in

(the variable to store the hack for radios turning out to spell radioshack was purely coincidental) :P

comment:5 @helgatheviking3 years ago

  • Version changed from 3.0 to trunk

This is still happening for me running the nightly WP 3.5-alpha-21751. Radio buttons in metaboxes lose their visual indication of being checked even though it is still there in the markup.

jqueryui said this bug was fixed years ago with the 1.6 version, but WP is running 1.9 and I'm still seeing this behavior.
http://bugs.jqueryui.com/ticket/2930

comment:6 @SergeyBiryukov3 years ago

  • Version changed from trunk to 3.0

Version number indicates when the bug was initially introduced/reported.

@helgatheviking3 years ago

delete mode = 'clone' for sortables

comment:7 @helgatheviking3 years ago

Sorry about the version change.

Removing the helper: 'clone', in the .sortable function reverts jquery ui sortable to its default of 'original'.... which seems to work fine for preserving the radio buttons.

See this fiddle for a live example: http://jsfiddle.net/NW7zD/3/

Then change the helper to 'clone' like it is in postbox.js and you'll see the radio button loses its checked marker.

I'm testing this on my local install of WP and I don't see any negative effects yet.

comment:8 @scribu3 years ago

  • Keywords has-patch needs-testing added; needs-patch removed
  • Milestone changed from Future Release to 3.5

comment:9 @SergeyBiryukov3 years ago

helper: 'clone' was added in [10834].

@lessbloat3 years ago

comment:10 @lessbloat3 years ago

switch postbox sortable mode.patch appeared to work but it auto-closed the dragged box in FF.

16972.2.diff works in FF, but auto-closed the dragged box in Chrome. :-)

Thought I'd post it anyway to expose the issue.

@lessbloat3 years ago

comment:11 @lessbloat3 years ago

16972.3.diff should fix the issue. Tested in Mac FF & Chrome, Win IE7 & FF.

comment:12 @MikeHansenMe2 years ago

Tested 16972.3.diff and it works well. I did not experience any trouble in FF or Chrome.

comment:13 @nacin2 years ago

  • Owner changed from ldebrouwer to azaozz

comment:14 @nacin2 years ago

  • Milestone changed from 3.5 to Future Release

Remains an issue. Punting pending feedback that 16972.3.diff is the right course.

comment:15 @ocean9015 months ago

  • Focuses javascript added

Still an issue in 3.8.

comment:16 @MZAWeb12 months ago

Still an issue in 3.9

comment:17 @voldemortensen8 months ago

Refreshed lessbloats patch.

comment:18 @omarreiss6 months ago

16972.3.refresh.diff tested working with FF, Chrome and Safari on Mac OSX.

comment:19 @beelde4 months ago

Still an issue in 3.9.2

Note: See TracTickets for help on using tickets.