Skip to content

Commit

Permalink
Fix radio/checkboxes in repeat groups having values wiped. Closes CMB…
Browse files Browse the repository at this point in the history
  • Loading branch information
jtsternberg committed Aug 7, 2015
1 parent 520c90a commit 5e90092
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 10 additions & 4 deletions js/cmb2.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@ window.CMB2 = (function(window, document, $, undefined){
var isEditor = $newInput.hasClass( 'wp-editor-area' );
var oldFor = $newInput.attr( 'for' );
var oldVal = $newInput.attr( 'value' );
var type = $newInput.prop( 'type' );
var checkable = 'radio' === type || 'checkbox' === type ? oldVal : false;
// var $next = $newInput.next();
var attrs = {};
var newID, oldID;
Expand All @@ -369,18 +371,22 @@ window.CMB2 = (function(window, document, $, undefined){
}

// Clear out old values
if ( undefined !== typeof( oldVal ) && oldVal ) {
attrs.value = '';
if ( undefined !== typeof( oldVal ) && oldVal || checkable ) {
attrs.value = checkable ? checkable : '';
}

// Clear out textarea values
if ( 'TEXTAREA' === $newInput.prop('tagName') ) {
$newInput.html( '' );
}

if ( checkable ) {
$newInput.removeAttr( 'checked' );
}

$newInput
.removeClass( 'hasDatepicker' )
.attr( attrs ).val('');
.attr( attrs ).val( checkable ? checkable : '' );

// wysiwyg field
if ( isEditor ) {
Expand Down Expand Up @@ -485,7 +491,7 @@ window.CMB2 = (function(window, document, $, undefined){
};

cmb.emptyValue = function( evt, row ) {
$('input:not([type="button"]), textarea', row).val('');
$('input:not([type="button"]:not([type="radio"]):not([type="checkbox"]), textarea', row).val('');
};

cmb.addGroupRow = function( evt ) {
Expand Down
Loading

0 comments on commit 5e90092

Please sign in to comment.