Description
There is a bug when sorting Groups that have radio button input fields.
They way you sort is by swapping the values of the input fields between the two groups. You're attempting to treat radio
buttons the same as checkbox
by doing this in your cmb.shiftRows
function:
else if ( 'checkbox' === $element.attr('type') || 'radio' === $element.attr('type') ) {
inputVals[ index ]['$'].prop( 'checked', $element.is(':checked') );
$element.prop( 'checked', inputVals[ index ]['val'] );
}
Because you're iterating over each input element, you can't swap the checked
property one-for-one with radio buttons, because when you check a radio button from a group, the dom/browser unchecks the others within the radio button group. Example:
Group 1 [ ] A [X] B [ ] C
Group 2 [X] A [ ] B [ ] C
On the first iteration, the checked
property for A is set in the first group but that unchecks B:
Group 1 [X] A [ ] B [ ] C
Group 2 [ ] A [ ] B [ ] C
Now on the second iteration, B is unchecked in Group 1, so B will never get checked for Group 2.
To solve this, I saved the checked states in a temporary attribute and then set the checked property at the end:
// And swap them all
$goto.find( cmb.repeatEls ).each( function( index ) {
...
// handle checkbox swapping
else if ( 'checkbox' === $element.attr('type') ) {
inputVals[ index ]['$'].prop( 'checked', $element.is(':checked') );
$element.prop( 'checked', inputVals[ index ]['val'] );
}
// handle radio swapping
else if ( 'radio' === $element.attr( 'type' ) ) {
if ($element.is(':checked')) {
inputVals[index]['$'].attr('data-checked', 'true');
}
if (inputVals[index]['$'].is(':checked')) {
$element.attr('data-checked', 'true');
}
}
...
});
$parent.find("input[data-checked=true]").prop('checked', true).removeAttr('data-checked');
$goto.find("input[data-checked=true]").prop('checked', true).removeAttr('data-checked');
Activity